devel #73

Merged
PlexSheep merged 27 commits from devel into master 2024-03-01 21:20:30 +01:00
8 changed files with 8 additions and 201 deletions
Showing only changes of commit c3cc64699c - Show all commits

View File

@ -9,13 +9,13 @@ pub use num_traits::{PrimInt, ToPrimitive};
/// * `data` - The data you are trying to dump /// * `data` - The data you are trying to dump
pub fn bytes_to_bin(data: &[u8]) -> String { pub fn bytes_to_bin(data: &[u8]) -> String {
let mut s = format!("0b{:08b}", data.first().unwrap()); let mut s = format!("0b{:08b}", data.first().unwrap());
for i in 1..data.len() { for dat in data {
s.push_str(&format!("_{:08b}", data[i])); s.push_str(&format!("_{:08b}", dat));
if i % 8 == 0 { if dat % 8 == 0 {
s.push_str("\n") s.push('\n')
} }
} }
return s; s
} }
/// Quickly format a number of Bytes [`usize`] with the corresponding /// Quickly format a number of Bytes [`usize`] with the corresponding

View File

@ -6,33 +6,7 @@
//! This crate implements core functionality useful for many use cases, such as macros, //! This crate implements core functionality useful for many use cases, such as macros,
//! formatting functions and more. //! formatting functions and more.
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
// we want docs
#![warn(missing_docs)]
#![warn(rustdoc::missing_crate_level_docs)]
////////////////////////////////////////////////////////////////////////////////////////////////////
// we want Debug everywhere.
#![warn(missing_debug_implementations)]
////////////////////////////////////////////////////////////////////////////////////////////////////
// enable clippy's extra lints, the pedantic version
#![warn(clippy::pedantic)]
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
/// macros to make things faster in your code /// macros to make things faster in your code
pub mod macros; pub mod macros;
/// some general use printing to stdout tools /// some general use printing to stdout tools
pub mod printing; pub mod printing;
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
//// STATICS ///////////////////////////////////////////////////////////////////////////////////////
//// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
//// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
//// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////

View File

@ -2,33 +2,15 @@
//! //!
//! This module implements macros for use with `libpt`. //! This module implements macros for use with `libpt`.
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
// we want docs
#![warn(missing_docs)]
#![warn(rustdoc::missing_crate_level_docs)]
////////////////////////////////////////////////////////////////////////////////////////////////////
// we want Debug everywhere.
#![warn(missing_debug_implementations)]
////////////////////////////////////////////////////////////////////////////////////////////////////
// enable clippy's extra lints, the pedantic version
#![warn(clippy::pedantic)]
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
pub use crate::get_stdout_for; pub use crate::get_stdout_for;
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
//// STATICS ///////////////////////////////////////////////////////////////////////////////////////
//// MACROS ////////////////////////////////////////////////////////////////////////////////////////
/// ## catches what the expression would write to the `stdout` /// ## catches what the expression would write to the `stdout`
/// ///
/// This macro takes an expression, executes it, and catches what it would write to the stdout. /// This macro takes an expression, executes it, and catches what it would write to the stdout.
/// The buffer of the stdout will then be returned for further use. /// The buffer of the stdout will then be returned for further use.
/// ///
/// This is especially useful when testing loggers or other frontend CLI functions. /// This is especially useful when testing loggers or other frontend CLI functions.
///
/// Inspiration: [users.rust-lang.org](https://users.rust-lang.org/t/how-to-test-functions-that-use-println/67188/5)
#[macro_export] #[macro_export]
macro_rules! get_stdout_for { macro_rules! get_stdout_for {
($test:expr) => {{ ($test:expr) => {{
@ -46,13 +28,3 @@ macro_rules! get_stdout_for {
output output
}}; }};
} }
//// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
//// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
//// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////

View File

@ -1,26 +1,9 @@
//! # tools that make printing stuff better //! # tools that make printing stuff better
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
// we want docs
#![warn(missing_docs)]
#![warn(rustdoc::missing_crate_level_docs)]
// we want Debug everywhere.
#![warn(missing_debug_implementations)]
// enable clippy's extra lints, the pedantic version
#![warn(clippy::pedantic)]
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
// reimport our macros to this module, so the user does not get confused when importing the macros // reimport our macros to this module, so the user does not get confused when importing the macros
pub use crate::divider; pub use crate::divider;
pub use crate::print_divider; pub use crate::print_divider;
//// TYPES /////////////////////////////////////////////////////////////////////////////////////////
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
//// STATICS ///////////////////////////////////////////////////////////////////////////////////////
//// MACROS ////////////////////////////////////////////////////////////////////////////////////////
/// Quickly get a one line visual divider /// Quickly get a one line visual divider
#[macro_export] #[macro_export]
macro_rules! divider { macro_rules! divider {
@ -29,7 +12,6 @@ macro_rules! divider {
}}; }};
} }
////////////////////////////////////////////////////////////////////////////////////////////////////
/// Quickly print a one line visual divider /// Quickly print a one line visual divider
#[macro_export] #[macro_export]
macro_rules! print_divider { macro_rules! print_divider {
@ -37,13 +19,3 @@ macro_rules! print_divider {
println!("{}", divider!()) println!("{}", divider!())
}}; }};
} }
//// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
//// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
//// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////

View File

@ -2,29 +2,9 @@
//! //!
//! This module handles errors in logging contexts. //! This module handles errors in logging contexts.
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
// we want docs
#![warn(missing_docs)]
#![warn(rustdoc::missing_crate_level_docs)]
// we want Debug everywhere.
#![warn(missing_debug_implementations)]
// enable clippy's extra lints, the pedantic version
#![warn(clippy::pedantic)]
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
use anyhow; use anyhow;
use thiserror::Error; use thiserror::Error;
use tracing::subscriber::SetGlobalDefaultError; use tracing::subscriber::SetGlobalDefaultError;
//// TYPES /////////////////////////////////////////////////////////////////////////////////////////
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
//// STATICS ///////////////////////////////////////////////////////////////////////////////////////
//// MACROS ////////////////////////////////////////////////////////////////////////////////////////
//// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
/// ## Errors for the [Logger](super::Logger) /// ## Errors for the [Logger](super::Logger)
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum Error { pub enum Error {
@ -41,11 +21,3 @@ pub enum Error {
#[error(transparent)] #[error(transparent)]
Other(#[from] anyhow::Error), Other(#[from] anyhow::Error),
} }
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
//// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
//// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////

View File

@ -14,9 +14,6 @@
//! - [`tracing_appender`]: Used to log to files //! - [`tracing_appender`]: Used to log to files
//! - [`tracing_subscriber`]: Used to do actual logging, formatting, to stdout //! - [`tracing_subscriber`]: Used to do actual logging, formatting, to stdout
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
use std::{ use std::{
fmt, fmt,
ops::Deref, ops::Deref,
@ -41,8 +38,6 @@ use tracing_subscriber::{
}; };
use anyhow::{bail, Result}; use anyhow::{bail, Result};
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
/// The log level used when none is specified /// The log level used when none is specified
pub const DEFAULT_LOG_LEVEL: Level = Level::INFO; pub const DEFAULT_LOG_LEVEL: Level = Level::INFO;
/// The path where logs are stored when no path is given. /// The path where logs are stored when no path is given.
@ -50,17 +45,14 @@ pub const DEFAULT_LOG_LEVEL: Level = Level::INFO;
/// Currently, this is `/dev/null`, meaning they will be written to the void = discarded. /// Currently, this is `/dev/null`, meaning they will be written to the void = discarded.
pub const DEFAULT_LOG_DIR: &'static str = "/dev/null"; pub const DEFAULT_LOG_DIR: &'static str = "/dev/null";
//// STATICS ///////////////////////////////////////////////////////////////////////////////////////
static INITIALIZED: AtomicBool = AtomicBool::new(false); static INITIALIZED: AtomicBool = AtomicBool::new(false);
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
/// ## Logger for [`pt`](../libpt/index.html) /// ## Logger for [`pt`](../libpt/index.html)
/// ///
/// This struct exists mainly for the python module, so that we can use the same logger with both /// This struct exists mainly for the python module, so that we can use the same logger with both
/// python and rust. /// python and rust.
pub struct Logger; pub struct Logger;
//// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
/// ## Main implementation /// ## Main implementation
impl Logger { impl Logger {
/// ## create a `Logger` /// ## create a `Logger`
@ -117,6 +109,8 @@ impl Logger {
) )
} }
// TODO: make the args a struct for easy access
//
/// ## initializes the logger /// ## initializes the logger
/// ///
/// Will enable the logger to be used. /// Will enable the logger to be used.
@ -262,7 +256,6 @@ impl Logger {
} }
} }
////////////////////////////////////////////////////////////////////////////////////////////////////
impl fmt::Debug for Logger { impl fmt::Debug for Logger {
/// ## DEBUG representation for [`Logger`] /// ## DEBUG representation for [`Logger`]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -274,9 +267,6 @@ impl fmt::Debug for Logger {
} }
} }
//// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
fn new_file_appender(log_dir: PathBuf) -> NonBlocking { fn new_file_appender(log_dir: PathBuf) -> NonBlocking {
let file_appender = tracing_appender::rolling::daily(log_dir.clone(), "log"); let file_appender = tracing_appender::rolling::daily(log_dir.clone(), "log");
return tracing_appender::non_blocking(file_appender).0; return tracing_appender::non_blocking(file_appender).0;

View File

@ -1,41 +0,0 @@
//! # Calculate expressions
//!
//! This crate is part of [`pt`](../libpt/index.html), but can also be used as a standalone
//! module.
//!
//! Calculate Calculations with your Calculator (`ccc`)
//!
//! This modules aim is to take a term of any kind ([String]) and calculate it's value, be it
//! variable based or a concrete numerical value. It implements different operators and
//! (mathematical) functions.
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
// we want docs
#![warn(missing_docs)]
#![warn(rustdoc::missing_crate_level_docs)]
// we want Debug everywhere.
#![warn(missing_debug_implementations)]
// enable clippy's extra lints, the pedantic version
#![warn(clippy::pedantic)]
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
//// TYPES /////////////////////////////////////////////////////////////////////////////////////////
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
//// STATICS ///////////////////////////////////////////////////////////////////////////////////////
//// MACROS ////////////////////////////////////////////////////////////////////////////////////////
//// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
//// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
//// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -3,36 +3,4 @@
//! This crate is part of [`pt`](../libpt/index.html), but can also be used as a standalone //! This crate is part of [`pt`](../libpt/index.html), but can also be used as a standalone
//! module. //! module.
//! //!
//! This module is currently empty, but will contain many math functionalities in a future version. //! This crate is currently empty, but will contain many math functionalities in a future version.
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
// we want docs
#![warn(missing_docs)]
#![warn(rustdoc::missing_crate_level_docs)]
// we want Debug everywhere.
#![warn(missing_debug_implementations)]
// enable clippy's extra lints, the pedantic version
#![warn(clippy::pedantic)]
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
pub mod ccc;
//// TYPES /////////////////////////////////////////////////////////////////////////////////////////
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
//// STATICS ///////////////////////////////////////////////////////////////////////////////////////
//// MACROS ////////////////////////////////////////////////////////////////////////////////////////
//// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
//// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
//// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////