-
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.
Breaking change Move return type of objects from HashMap<String, Vec<Object>> to HashMap<String, ObjectEntry> where ObjectEntry is an enum of Object(Object) or List(Vec<Object>) Then, when reading files, allow either defining object/foo/*.toml or object/foo.toml. In the latter case, objects.foo will be an object itself rather than an array, and there will only ever be one of them. If both are defined, the build will fail.
- Loading branch information
1 parent
114dc3d
commit 94a7b4c
Showing
10 changed files
with
215 additions
and
66 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
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,18 +1,25 @@ | ||
#[cfg(feature = "binary")] | ||
use archival::binary; | ||
use tracing_subscriber::{fmt, prelude::*, EnvFilter}; | ||
|
||
fn main() { | ||
tracing_subscriber::registry() | ||
.with(fmt::layer()) | ||
.with(EnvFilter::from_default_env()) | ||
.init(); | ||
#[cfg(feature = "binary")] | ||
match binary::binary(std::env::args()) { | ||
Ok(c) => std::process::exit(c.code()), | ||
Err(e) => { | ||
eprintln!("Error: {e}"); | ||
std::process::exit(1); | ||
binary::main(); | ||
#[cfg(not(feature = "binary"))] | ||
println!("archival was built without the binary feature.") | ||
} | ||
|
||
#[cfg(feature = "binary")] | ||
mod binary { | ||
use archival::binary; | ||
use tracing_subscriber::{fmt, prelude::*, EnvFilter}; | ||
pub fn main() { | ||
tracing_subscriber::registry() | ||
.with(fmt::layer()) | ||
.with(EnvFilter::from_default_env()) | ||
.init(); | ||
match binary::binary(std::env::args()) { | ||
Ok(c) => std::process::exit(c.code()), | ||
Err(e) => { | ||
eprintln!("Error: {e}"); | ||
std::process::exit(1); | ||
} | ||
} | ||
} | ||
} |
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,99 @@ | ||
use crate::object::Object; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
#[cfg_attr(feature = "typescript", derive(typescript_type_def::TypeDef))] | ||
pub enum ObjectEntry { | ||
List(Vec<Object>), | ||
Object(Object), | ||
} | ||
|
||
impl ObjectEntry { | ||
pub fn from_vec(vec: Vec<Object>) -> Self { | ||
Self::List(vec) | ||
} | ||
pub fn from_object(object: Object) -> Self { | ||
Self::Object(object) | ||
} | ||
} | ||
|
||
pub struct ObjectEntryIterator<'a> { | ||
entry: &'a ObjectEntry, | ||
index: usize, | ||
} | ||
|
||
impl<'a> Iterator for ObjectEntryIterator<'a> { | ||
type Item = &'a Object; | ||
fn next(&mut self) -> Option<Self::Item> { | ||
match self.entry { | ||
ObjectEntry::List(l) => { | ||
let o = l.get(self.index); | ||
self.index += 1; | ||
o | ||
} | ||
ObjectEntry::Object(o) => { | ||
if self.index == 0 { | ||
self.index = usize::MAX; | ||
Some(o) | ||
} else { | ||
None | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl<'a> ObjectEntry { | ||
pub fn iter_mut(&'a mut self) -> ObjectEntryMutIterator<'a> { | ||
self.into_iter() | ||
} | ||
} | ||
|
||
impl<'a> IntoIterator for &'a ObjectEntry { | ||
type Item = &'a Object; | ||
type IntoIter = ObjectEntryIterator<'a>; | ||
|
||
fn into_iter(self) -> Self::IntoIter { | ||
ObjectEntryIterator { | ||
entry: self, | ||
index: 0, | ||
} | ||
} | ||
} | ||
|
||
impl<'a> IntoIterator for &'a mut ObjectEntry { | ||
type Item = &'a mut Object; | ||
type IntoIter = ObjectEntryMutIterator<'a>; | ||
|
||
fn into_iter(self) -> Self::IntoIter { | ||
ObjectEntryMutIterator { | ||
entry: self, | ||
index: 0, | ||
} | ||
} | ||
} | ||
pub struct ObjectEntryMutIterator<'a> { | ||
entry: &'a mut ObjectEntry, | ||
index: usize, | ||
} | ||
|
||
impl<'a> Iterator for ObjectEntryMutIterator<'a> { | ||
type Item = &'a mut Object; | ||
fn next(&mut self) -> Option<Self::Item> { | ||
match self.entry { | ||
ObjectEntry::List(l) => { | ||
let o = l.get_mut(self.index); | ||
self.index += 1; | ||
unsafe { std::mem::transmute(o) } | ||
} | ||
ObjectEntry::Object(o) => { | ||
if self.index == 0 { | ||
self.index = usize::MAX; | ||
unsafe { std::mem::transmute(o) } | ||
} else { | ||
None | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.