-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Szune/dev
Add serializing/deserializing ipv4
- Loading branch information
Showing
13 changed files
with
181 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,6 +1,6 @@ | ||
[package] | ||
name = "aeon" | ||
version = "0.2.0" | ||
version = "0.3.0" | ||
authors = ["Szune <[email protected]>"] | ||
edition = "2018" | ||
description = "A configuration file format with macros for brevity." | ||
|
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,20 @@ | ||
use std::ops::{BitAnd, BitOrAssign}; | ||
|
||
#[inline] | ||
pub fn has<T>(value: T, flag: T) -> bool | ||
where | ||
T: BitAnd<Output = T> + | ||
Copy + | ||
PartialEq + | ||
Eq, | ||
{ | ||
value & flag == flag | ||
} | ||
|
||
#[inline] | ||
pub fn add<T>(value: &mut T, flag: T) -> () | ||
where | ||
T: BitOrAssign + Copy | ||
{ | ||
*value |= flag; | ||
} |
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ pub enum Token { | |
String(String), | ||
Integer(i64), | ||
Double(f64), | ||
Ip(std::net::IpAddr), | ||
At, | ||
True, | ||
False, | ||
|
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 |
---|---|---|
|
@@ -9,4 +9,5 @@ pub enum AeonValue { | |
Double(f64), | ||
Map(HashMap<String,AeonValue>), | ||
List(Vec<AeonValue>), | ||
Ip(std::net::IpAddr), | ||
} |
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,14 +1,39 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use aeon::convert::{AeonObjectConvert, AeonConvert}; | ||
use aeon::value::AeonValue; | ||
|
||
#[test] | ||
pub fn deserialize_map_with_both_quoted_and_not_quoted_keys() { | ||
let mut aeon = r#"map: {test: 1, "two": 2}"#.into(); | ||
let aeon = r#"map: {test: 1, "two": 2}"#.into(); | ||
let ser = aeon::deserialize(aeon).expect("failed to deserialize"); | ||
|
||
assert_eq!(ser.get_path("map/test").int(), Some(1)); | ||
assert_eq!(ser.get_path("map/two").int(), Some(2)); | ||
} | ||
|
||
#[test] | ||
pub fn deserialize_double() { | ||
let aeon = r#"doub: 2.10"#.into(); | ||
let ser = aeon::deserialize(aeon).expect("failed to deserialize"); | ||
|
||
assert_eq!(ser.get("doub").double(), Some(2.10)); | ||
} | ||
|
||
#[test] | ||
pub fn deserialize_ip() { | ||
let aeon = r#"ip: 127.2.3.4"#.into(); | ||
let ser = aeon::deserialize(aeon).expect("failed to deserialize"); | ||
|
||
assert_eq!(ser.get("ip").ip(), | ||
Some(std::net::IpAddr::V4(std::net::Ipv4Addr::new(127,2,3,4)))); | ||
} | ||
|
||
#[test] | ||
pub fn deserialize_ip_and_get_as_string() { | ||
let aeon = r#"ip: 127.2.3.4"#.into(); | ||
let ser = aeon::deserialize(aeon).expect("failed to deserialize"); | ||
|
||
assert_eq!(ser.get("ip").ip_str(), | ||
Some(String::from("127.2.3.4"))); | ||
} | ||
} |
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