BrdbInterned

Struct BrdbInterned 

Source
pub struct BrdbInterned(/* private fields */);

Implementations§

Source§

impl BrdbInterned

Source

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}
Source

pub fn get_or<'b, 'a: 'b>(self, schema: &'a BrdbSchema, or: &'b str) -> &'b str

Source

pub fn get_or_else( self, schema: &BrdbSchema, or: impl FnMut() -> String, ) -> String

Source

pub fn get_ok( self, schema: &BrdbSchema, or: impl FnMut() -> BrdbSchemaError, ) -> Result<&str, BrdbSchemaError>

Trait Implementations§

Source§

impl Clone for BrdbInterned

Source§

fn clone(&self) -> BrdbInterned

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BrdbInterned

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for BrdbInterned

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for BrdbInterned

Source§

fn eq(&self, other: &BrdbInterned) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for BrdbInterned

Source§

impl Eq for BrdbInterned

Source§

impl StructuralPartialEq for BrdbInterned

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.