-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
struct logger to datalogger end to end
- Loading branch information
Showing
11 changed files
with
125 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
[workspace] | ||
members = ["copper", "copper_log_test", "copper_derive", "copper_derive_test", "copper_log", "examples/config_gen", "examples/pluginload", "examples/simplelogger", "examples/v4lsrc", "copper_log_runtime", "copper_datalogger", "copper_clock"] | ||
members = ["copper", | ||
"copper_log_test", | ||
"copper_derive", | ||
"copper_derive_test", | ||
"copper_log", | ||
"examples/config_gen", | ||
"examples/pluginload", | ||
"examples/simplelogger", | ||
"examples/v4lsrc", | ||
"copper_log_runtime", | ||
"copper_datalogger", | ||
"copper_clock", | ||
"copper_traits"] | ||
resolver = "2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
name = "copper_datalogger" | ||
name = "copper-datalogger" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "copper-traits" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
bincode = "2.0.0-rc.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use bincode::Encode; | ||
use std::error::Error; | ||
use std::fmt::{Display, Formatter}; | ||
|
||
/// Common copper Error type. | ||
#[derive(Debug)] | ||
pub struct CuError { | ||
message: String, | ||
context: Option<String>, | ||
} | ||
|
||
impl Display for CuError { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
let context_str = match &self.context { | ||
Some(c) => format!("{}", c), | ||
None => "None".to_string(), | ||
}; | ||
write!(f, "{}\n context:{}", self.message, context_str)?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Error for CuError {} | ||
|
||
impl From<&str> for CuError { | ||
fn from(s: &str) -> CuError { | ||
CuError { | ||
message: s.to_string(), | ||
context: None, | ||
} | ||
} | ||
} | ||
|
||
impl From<String> for CuError { | ||
fn from(s: String) -> CuError { | ||
CuError { | ||
message: s, | ||
context: None, | ||
} | ||
} | ||
} | ||
|
||
impl CuError { | ||
pub fn add_context(mut self, context: &str) -> CuError { | ||
self.context = Some(context.into()); | ||
self | ||
} | ||
} | ||
|
||
// Generic Result type for copper. | ||
pub type CuResult<T> = Result<T, CuError>; | ||
|
||
/// Defines a basic write, append only stream trait to be able to log or send serializable objects. | ||
pub trait Stream: Sync + Send { | ||
fn log(&mut self, obj: &impl Encode) -> CuResult<()>; | ||
} |