pub struct BrdbInterned(/* private fields */);Implementations§
Source§impl BrdbInterned
impl BrdbInterned
Sourcepub fn get(self, schema: &BrdbSchema) -> Option<&str>
pub fn get(self, schema: &BrdbSchema) -> Option<&str>
Examples found in repository?
examples/read_all_schemas.rs (line 44)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 // world file from argv
7 let filename = std::env::args()
8 .nth(1)
9 .unwrap_or_else(|| "world.brdb".to_string());
10 let path = PathBuf::from(filename);
11 if !path.exists() {
12 eprintln!("File does not exist: {}", path.display());
13 std::process::exit(1);
14 }
15
16 let db = Brdb::open(&path)?.into_reader();
17
18 let schemas_dir = path.with_extension("schemas");
19 if schemas_dir.exists() {
20 std::fs::remove_dir_all(&schemas_dir)?;
21 }
22 std::fs::create_dir_all(&schemas_dir)?;
23
24 db.get_fs()?.for_each(&mut |f| {
25 if !f.is_file() || !f.name().ends_with(".schema") {
26 return;
27 }
28 println!("Reading schema file: {}... ", f.name());
29
30 let Ok(buf) = f.read(&*db) else {
31 eprintln!("Failed to read schema file: {}", f.name());
32 return;
33 };
34
35 let Ok(schema) = BrdbSchema::read(buf.as_slice()) else {
36 eprintln!("Failed to parse schema file: {}", f.name());
37 return;
38 };
39 let soa = schema
40 .structs
41 .last()
42 .unwrap()
43 .0
44 .get(&schema)
45 .unwrap()
46 .to_string();
47
48 if let Err(e) = std::fs::write(
49 schemas_dir.join(soa).with_extension("schema"),
50 schema.to_string(),
51 ) {
52 eprintln!("Failed to write schema file: {}: {}", f.name(), e);
53 }
54 });
55
56 Ok(())
57}pub fn get_or<'b, 'a: 'b>(self, schema: &'a BrdbSchema, or: &'b str) -> &'b str
pub fn get_or_else( self, schema: &BrdbSchema, or: impl FnMut() -> String, ) -> String
pub fn get_ok( self, schema: &BrdbSchema, or: impl FnMut() -> BrdbSchemaError, ) -> Result<&str, BrdbSchemaError>
Trait Implementations§
Source§impl Clone for BrdbInterned
impl Clone for BrdbInterned
Source§fn clone(&self) -> BrdbInterned
fn clone(&self) -> BrdbInterned
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BrdbInterned
impl Debug for BrdbInterned
Source§impl Hash for BrdbInterned
impl Hash for BrdbInterned
Source§impl PartialEq for BrdbInterned
impl PartialEq for BrdbInterned
impl Copy for BrdbInterned
impl Eq for BrdbInterned
impl StructuralPartialEq for BrdbInterned
Auto Trait Implementations§
impl Freeze for BrdbInterned
impl RefUnwindSafe for BrdbInterned
impl Send for BrdbInterned
impl Sync for BrdbInterned
impl Unpin for BrdbInterned
impl UnwindSafe for BrdbInterned
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more