### pub fn get<'a>(&self, key: impl Borrow>) -> Result>> Source: https://docs.rs/redb/4.1.0/redb/struct.ReadOnlyTable.html Retrieves the value associated with the given key. The returned AccessGuard is reference counted and keeps the transaction alive until dropped. ```APIDOC ## pub fn get<'a>(&self, key: impl Borrow>) -> Result>> ### Description Retrieves the value associated with the given key. The returned AccessGuard is reference counted and keeps the transaction alive until dropped. ``` -------------------------------- ### get Source: https://docs.rs/redb/4.1.0/redb/struct.Table.html Retrieves the value corresponding to the given key from the table. ```APIDOC ## fn get<'a>( &self, key: impl Borrow>, ) -> Result>> ### Description Returns the value corresponding to the given key. ``` -------------------------------- ### MutInPlaceValue Implementation for &[u8] Source: https://docs.rs/redb/4.1.0/redb/trait.MutInPlaceValue.html Example implementation of MutInPlaceValue for the byte slice type. ```rust impl MutInPlaceValue for &[u8] type BaseRefType = [u8] fn initialize(_data: &mut [u8]) fn from_bytes_mut(data: &mut [u8]) -> &mut Self::BaseRefType ``` -------------------------------- ### get Source: https://docs.rs/redb/4.1.0/redb/struct.ReadOnlyMultimapTable.html Retrieves an iterator over all values for the given key. The returned iterator is reference counted and keeps the transaction alive until it is dropped. ```APIDOC pub fn get<'a>(&self, key: impl Borrow>) -> Result> ``` -------------------------------- ### Basic database usage Source: https://docs.rs/redb/4.1.0/redb/struct.Database.html Demonstrates creating a database, opening a table, inserting data, and committing a write transaction. ```rust use redb::*; const TABLE: TableDefinition = TableDefinition::new("my_data"); let db = Database::create(filename)?; let write_txn = db.begin_write()?; { let mut table = write_txn.open_table(TABLE)?; table.insert(&0, &0)?; } write_txn.commit()?; ``` -------------------------------- ### Perform Basic Database Operations Source: https://docs.rs/redb/4.1.0/redb/index.html Demonstrates creating a database, performing a write transaction to insert data, and executing a read transaction to retrieve it. ```rust use redb::{Database, Error, ReadableDatabase, ReadableTable, TableDefinition}; const TABLE: TableDefinition<&str, u64> = TableDefinition::new("my_data"); fn main() -> Result<(), Error> { let file = tempfile::NamedTempFile::new().unwrap(); let db = Database::create(file.path())?; let write_txn = db.begin_write()?; { let mut table = write_txn.open_table(TABLE)?; table.insert("my_key", &123)?; } write_txn.commit()?; let read_txn = db.begin_read()?; let table = read_txn.open_table(TABLE)?; assert_eq!(table.get("my_key")?.unwrap().value(), 123); Ok(()) } ``` -------------------------------- ### Builder::create Source: https://docs.rs/redb/4.1.0/redb/struct.Builder.html Initializes or opens a database at the specified path. ```APIDOC ## pub fn create(&self, path: impl AsRef) -> Result ### Description Opens the specified file as a redb database. If the file does not exist or is empty, a new database is initialized. ``` -------------------------------- ### Database::create Source: https://docs.rs/redb/4.1.0/redb/struct.Database.html Opens the specified file as a redb database. If the file does not exist or is empty, a new database is initialized. ```APIDOC ## Database::create ### Description Opens the specified file as a redb database. If the file does not exist, or is an empty file, a new database will be initialized in it. If the file is a valid redb database, it will be opened. ### Signature `pub fn create(path: impl AsRef) -> Result` ``` -------------------------------- ### Open and read from a database Source: https://docs.rs/redb/4.1.0/redb/struct.ReadOnlyDatabase.html Demonstrates creating a database, writing data, and then opening it in read-only mode to perform a read transaction. ```rust use redb::*; const TABLE: TableDefinition = TableDefinition::new("my_data"); let db = Database::create(filename)?; let txn = db.begin_write()?; { let mut table = txn.open_table(TABLE)?; table.insert(&0, &0)?; } txn.commit()?; drop(db); let db = ReadOnlyDatabase::open(filename)?; let txn = db.begin_read()?; { let mut table = txn.open_table(TABLE)?; println!("{}", table.get(&0)?.unwrap().value()); } ``` -------------------------------- ### Builder::create_with_backend Source: https://docs.rs/redb/4.1.0/redb/struct.Builder.html Opens or creates a database using a custom storage backend. ```APIDOC ## pub fn create_with_backend(&self, backend: impl StorageBackend) -> Result ### Description Open an existing or create a new database with the given backend. ``` -------------------------------- ### Builder::open Source: https://docs.rs/redb/4.1.0/redb/struct.Builder.html Opens an existing redb database. ```APIDOC ## pub fn open(&self, path: impl AsRef) -> Result ### Description Opens an existing redb database. ``` -------------------------------- ### Builder::create_file Source: https://docs.rs/redb/4.1.0/redb/struct.Builder.html Opens or creates a database using a provided File handle. ```APIDOC ## pub fn create_file(&self, file: File) -> Result ### Description Open an existing or create a new database in the given file. The file must be empty or contain a valid database. ``` -------------------------------- ### FileBackend::new Source: https://docs.rs/redb/4.1.0/redb/backends/struct.FileBackend.html Creates a new FileBackend instance that stores data to the provided file. ```APIDOC ## pub fn new(file: File) -> Result ### Description Creates a new backend which stores data to the given file. ### Parameters - **file** (File) - Required - The file handle to be used for storage. ``` -------------------------------- ### Product implementation for Result Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Demonstrates using the product method on an iterator of Results, which short-circuits on the first Err encountered. ```rust let nums = vec!["5", "10", "1", "2"]; let total: Result = nums.iter().map(|w| w.parse::()).product(); assert_eq!(total, Ok(100)); let nums = vec!["5", "10", "one", "2"]; let total: Result = nums.iter().map(|w| w.parse::()).product(); assert!(total.is_err()); ``` -------------------------------- ### Database::open Source: https://docs.rs/redb/4.1.0/redb/struct.Database.html Opens an existing redb database from the specified path. ```APIDOC ## Database::open ### Description Opens an existing redb database. ### Signature `pub fn open(path: impl AsRef) -> Result` ``` -------------------------------- ### begin_read Source: https://docs.rs/redb/4.1.0/redb/struct.Database.html Begins a read transaction on the database. ```APIDOC ### fn begin_read(&self) -> Result Begins a read transaction for the database instance. ``` -------------------------------- ### open_table Source: https://docs.rs/redb/4.1.0/redb/struct.WriteTransaction.html Opens a table, creating it if it does not exist. ```APIDOC ## pub fn open_table<'txn, K: Key + 'static, V: Value + 'static>( &'txn self, definition: TableDefinition<'_, K, V>, ) -> Result, TableError> ### Description Opens the specified table. If the table does not exist, it will be created. ``` -------------------------------- ### Builder::new Source: https://docs.rs/redb/4.1.0/redb/struct.Builder.html Constructs a new Builder instance with default settings (cache_size_bytes: 1GiB). ```APIDOC ## pub fn new() -> Self ### Description Construct a new Builder with sensible defaults. ### Defaults - cache_size_bytes: 1GiB ``` -------------------------------- ### Constructing a MultimapTableDefinition Source: https://docs.rs/redb/4.1.0/redb/struct.MultimapTableDefinition.html Creates a new definition instance. Panics if the provided name is empty. ```rust pub const fn new(name: &'a str) -> Self ``` -------------------------------- ### Database::begin_write Source: https://docs.rs/redb/4.1.0/redb/struct.Database.html Begins a write transaction, allowing read and write operations on the database. ```APIDOC ## Database::begin_write ### Description Begins a write transaction. Returns a WriteTransaction which may be used to read/write to the database. Only a single write may be in progress at a time; this function will block if another write is in progress. ### Signature `pub fn begin_write(&self) -> Result` ``` -------------------------------- ### TableDefinition::new Source: https://docs.rs/redb/4.1.0/redb/struct.TableDefinition.html Constructs a new TableDefinition with the specified name. Panics if the name is empty. ```APIDOC ## pub const fn new(name: &'a str) -> Self ### Description Constructs a new table definition with the given name. This is used to identify the table when opening it via a transaction. ### Parameters - **name** (&str) - Required - The name of the table. Must not be empty. ### Panics Panics if the provided name is empty. ``` -------------------------------- ### open_multimap_table Source: https://docs.rs/redb/4.1.0/redb/struct.WriteTransaction.html Opens a multimap table, creating it if it does not exist. ```APIDOC ## pub fn open_multimap_table<'txn, K: Key + 'static, V: Key + 'static>( &'txn self, definition: MultimapTableDefinition<'_, K, V>, ) -> Result, TableError> ### Description Opens the specified multimap table. If the table does not exist, it will be created. ``` -------------------------------- ### Builder::open_read_only Source: https://docs.rs/redb/4.1.0/redb/struct.Builder.html Opens an existing redb database in read-only mode. ```APIDOC ## pub fn open_read_only(&self, path: impl AsRef) -> Result ### Description Opens an existing redb database in read-only mode. Returns DatabaseError::DatabaseAlreadyOpen if the file is already opened for writing on supported platforms. ``` -------------------------------- ### set_quick_repair Source: https://docs.rs/redb/4.1.0/redb/struct.WriteTransaction.html Enable or disable quick-repair mode for the database. ```APIDOC ## pub fn set_quick_repair(&mut self, enabled: bool) ### Description Enable or disable quick-repair. By default, this is disabled. When enabled, redb saves the allocator state during commits and uses 2-phase commit, making crash recovery almost instant at the cost of slower commits. ``` -------------------------------- ### TypeName::new Source: https://docs.rs/redb/4.1.0/redb/struct.TypeName.html Creates a new instance of TypeName with the specified name. ```APIDOC ## pub fn new(name: &str) -> Self ### Description Creates a new TypeName instance. It is recommended that the provided name be prefixed with the crate name to minimize the chance of colliding with other user-defined types. ### Parameters - **name** (&str) - Required - The name to assign to the TypeName instance. ``` -------------------------------- ### stats() Source: https://docs.rs/redb/4.1.0/redb/struct.ReadOnlyUntypedMultimapTable.html Retrieves information about storage usage for the table. ```APIDOC ## fn stats(&self) -> Result ### Description Retrieves information about storage usage for the table. ``` -------------------------------- ### first Source: https://docs.rs/redb/4.1.0/redb/struct.Table.html Retrieves the first key-value pair in the table. ```APIDOC ## fn first(&self) -> Result, AccessGuard<'_, V>)>> ### Description Returns the first key-value pair in the table, if it exists. ``` -------------------------------- ### Into Ok Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Extracts the Ok value without risk of panicking, intended for infallible results. ```rust fn only_good_news() -> Result { Ok("this is fine".into()) } let s: String = only_good_news().into_ok(); println!("{s}"); ``` -------------------------------- ### expect Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Returns the contained Ok value, consuming the self value, or panics if Err. ```APIDOC ## pub fn expect(self, msg: &str) -> T ### Description Returns the contained `Ok` value, consuming the `self` value. Panics if the value is an `Err`, with a panic message including the passed message, and the content of the `Err`. ``` -------------------------------- ### list_tables Source: https://docs.rs/redb/4.1.0/redb/struct.WriteTransaction.html Lists all tables in the database. ```APIDOC ## pub fn list_tables( &self, ) -> Result + '_> ### Description Returns an iterator over all tables currently in the database. ``` -------------------------------- ### MultimapTableDefinition::new Source: https://docs.rs/redb/4.1.0/redb/struct.MultimapTableDefinition.html Constructs a new MultimapTableDefinition with the specified name. Panics if the provided name is empty. ```APIDOC ## pub const fn new(name: &'a str) -> Self ### Description Constructs a new multimap table definition with the given name. ### Parameters - **name** (&str) - Required - The name of the multimap table. Must be non-empty. ### Panics Panics if the provided `name` is empty. ``` -------------------------------- ### Perform Range Query on Table Source: https://docs.rs/redb/4.1.0/redb/trait.ReadableTable.html Demonstrates using the range method to iterate over a subset of table entries. ```rust use redb::*; const TABLE: TableDefinition<&str, u64> = TableDefinition::new("my_data"); let db = Database::create(filename)?; let write_txn = db.begin_write()?; { let mut table = write_txn.open_table(TABLE)?; table.insert("a", &0)?; table.insert("b", &1)?; table.insert("c", &2)?; } write_txn.commit()?; let read_txn = db.begin_read()?; let table = read_txn.open_table(TABLE)?; let mut iter = table.range("a".."c")?; let (key, value) = iter.next().unwrap()?; assert_eq!("a", key.value()); assert_eq!(0, value.value()); ``` -------------------------------- ### ReadOnlyDatabase::begin_read Source: https://docs.rs/redb/4.1.0/redb/struct.ReadOnlyDatabase.html Begins a read transaction on the database. ```APIDOC ## fn begin_read(&self) -> Result ### Description Begins a read transaction, allowing the user to perform read operations on the database. ### Returns - **Result** - Returns a ReadTransaction object on success, or a TransactionError if the transaction could not be started. ``` -------------------------------- ### And Chaining Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Returns the provided result if the current result is Ok, otherwise returns the Err. ```rust let x: Result = Ok(2); let y: Result<&str, &str> = Err("late error"); assert_eq!(x.and(y), Err("late error")); let x: Result = Err("early error"); let y: Result<&str, &str> = Ok("foo"); assert_eq!(x.and(y), Err("early error")); let x: Result = Err("not a 2"); let y: Result<&str, &str> = Err("late error"); assert_eq!(x.and(y), Err("not a 2")); let x: Result = Ok(2); let y: Result<&str, &str> = Ok("different result type"); assert_eq!(x.and(y), Ok("different result type")); ``` -------------------------------- ### Provide fallback results with or Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Returns the current result if it is Ok, otherwise returns the provided alternative result. Note that arguments are eagerly evaluated. ```rust let x: Result = Ok(2); let y: Result = Err("late error"); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("early error"); let y: Result = Ok(2); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("not a 2"); let y: Result = Err("late error"); assert_eq!(x.or(y), Err("late error")); let x: Result = Ok(2); let y: Result = Ok(100); assert_eq!(x.or(y), Ok(2)); ``` -------------------------------- ### name Source: https://docs.rs/redb/4.1.0/redb/struct.Table.html Returns the name of the table. ```APIDOC ## fn name(&self) -> &str ### Description Returns the name of the table. ``` -------------------------------- ### stats Source: https://docs.rs/redb/4.1.0/redb/struct.WriteTransaction.html Retrieves database storage statistics. ```APIDOC ## pub fn stats(&self) -> Result ### Description Retrieves information regarding storage usage within the database. ``` -------------------------------- ### Unwrap Result or Default Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Returns the Ok value or the default value of the type if the result is an Err. ```rust let good_year_from_input = "1909"; let bad_year_from_input = "190blarg"; let good_year = good_year_from_input.parse().unwrap_or_default(); let bad_year = bad_year_from_input.parse().unwrap_or_default(); assert_eq!(1909, good_year); assert_eq!(0, bad_year); ``` -------------------------------- ### Database::compact Source: https://docs.rs/redb/4.1.0/redb/struct.Database.html Compacts the database file to reclaim space. ```APIDOC ## Database::compact ### Description Compacts the database file. Returns true if compaction was performed, and false if no further compaction was possible. ### Signature `pub fn compact(&mut self) -> Result` ``` -------------------------------- ### Retrieve values with unwrap_or Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Returns the contained Ok value or a provided default value. Arguments are eagerly evaluated. ```rust let default = 2; let x: Result = Ok(9); assert_eq!(x.unwrap_or(default), 9); let x: Result = Err("error"); assert_eq!(x.unwrap_or(default), default); ``` -------------------------------- ### StorageBackend Trait Definition Source: https://docs.rs/redb/4.1.0/redb/trait.StorageBackend.html The core trait definition for implementing custom storage backends in redb. ```rust pub trait StorageBackend: 'static + Debug + Send + Sync { // Required methods fn len(&self) -> Result; fn read(&self, offset: u64, out: &mut [u8]) -> Result<(), Error>; fn set_len(&self, len: u64) -> Result<(), Error>; fn sync_data(&self) -> Result<(), Error>; fn write(&self, offset: u64, data: &[u8]) -> Result<(), Error>; // Provided method fn close(&self) -> Result<(), Error> { ... } } ``` -------------------------------- ### ReadOnlyDatabase::open Source: https://docs.rs/redb/4.1.0/redb/struct.ReadOnlyDatabase.html Opens an existing redb database at the specified path in read-only mode. ```APIDOC ## pub fn open(path: impl AsRef) -> Result ### Description Opens an existing redb database. This allows for read-only access to the database file. ### Parameters - **path** (impl AsRef) - Required - The file system path to the existing redb database. ### Returns - **Result** - Returns a ReadOnlyDatabase instance on success, or a DatabaseError if the operation fails. ``` -------------------------------- ### len() Source: https://docs.rs/redb/4.1.0/redb/struct.ReadOnlyUntypedMultimapTable.html Returns the number of entries in the table. ```APIDOC ## fn len(&self) -> Result ### Description Returns the number of entries in the table. ``` -------------------------------- ### list_multimap_tables Source: https://docs.rs/redb/4.1.0/redb/struct.WriteTransaction.html Lists all multimap tables in the database. ```APIDOC ## pub fn list_multimap_tables( &self, ) -> Result + '_> ### Description Returns an iterator over all multimap tables currently in the database. ``` -------------------------------- ### is_empty() Source: https://docs.rs/redb/4.1.0/redb/struct.ReadOnlyUntypedMultimapTable.html Returns true if the table is empty. ```APIDOC ## fn is_empty(&self) -> Result ### Description Returns true if the table is empty. ``` -------------------------------- ### And Then Chaining Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Calls a function if the result is Ok, otherwise returns the Err. ```rust fn sq_then_to_string(x: u32) -> Result { x.checked_mul(x).map(|sq| sq.to_string()).ok_or("overflowed") } ``` -------------------------------- ### Database definition Source: https://docs.rs/redb/4.1.0/redb/struct.Database.html The internal structure of the Database type. ```rust pub struct Database { /* private fields */ } ``` -------------------------------- ### Expect Error Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Returns the Err value or panics if the result is an Ok. ```rust let x: Result = Ok(10); x.expect_err("Testing expect_err"); // panics with `Testing expect_err: 10` ``` -------------------------------- ### Sum implementation for Result Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Demonstrates using the sum method on an iterator of Results, which returns an Err if any element is an Err. ```rust let f = |&x: &i32| if x < 0 { Err("Negative element found") } else { Ok(x) }; let v = vec![1, 2]; let res: Result = v.iter().map(f).sum(); assert_eq!(res, Ok(3)); let v = vec![1, -2]; let res: Result = v.iter().map(f).sum(); assert_eq!(res, Err("Negative element found")); ``` -------------------------------- ### restore_savepoint Source: https://docs.rs/redb/4.1.0/redb/struct.WriteTransaction.html Restores the database state to a previously created savepoint. ```APIDOC ## pub fn restore_savepoint(&mut self, savepoint: &Savepoint) -> Result<(), SavepointError> ### Description Restore the state of the database to the given `Savepoint`. Calling this method invalidates all `Savepoint`s created after the provided savepoint. ``` -------------------------------- ### Expect Result Value Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Returns the Ok value or panics with a provided message if the result is Err. ```rust let x: Result = Err("emergency failure"); x.expect("Testing expect"); // panics with `Testing expect: emergency failure` ``` ```rust let path = std::env::var("IMPORTANT_PATH") .expect("env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`"); ``` -------------------------------- ### Retrieve values with unwrap_or_else Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Returns the contained Ok value or computes a default value using a closure. ```rust fn count(x: &str) -> usize { x.len() } ``` -------------------------------- ### Builder::set_cache_size Source: https://docs.rs/redb/4.1.0/redb/struct.Builder.html Configures the memory cache size for the database. ```APIDOC ## pub fn set_cache_size(&mut self, bytes: usize) -> &mut Self ### Description Set the amount of memory (in bytes) used for caching data. ``` -------------------------------- ### Reference Result with as_ref and as_mut Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Converts a Result to a Result containing references to the original values. ```rust let x: Result = Ok(2); assert_eq!(x.as_ref(), Ok(&2)); let x: Result = Err("Error"); assert_eq!(x.as_ref(), Err(&"Error")); ``` ```rust fn mutate(r: &mut Result) { match r.as_mut() { Ok(v) => *v = 42, Err(e) => *e = 0, } } let mut x: Result = Ok(2); mutate(&mut x); assert_eq!(x.unwrap(), 42); let mut x: Result = Err(13); mutate(&mut x); assert_eq!(x.unwrap_err(), 0); ``` -------------------------------- ### persistent_savepoint Source: https://docs.rs/redb/4.1.0/redb/struct.WriteTransaction.html Creates a snapshot of the current database state that can be used to rollback the database. This savepoint persists until explicitly deleted. ```APIDOC ## pub fn persistent_savepoint(&self) -> Result ### Description Creates a snapshot of the current database state, which can be used to rollback the database. This savepoint will exist until it is deleted with `delete_savepoint()`. ### Returns - `Result`: Returns the ID of the created savepoint, or an error if the transaction is dirty or immediate durability is required. ``` -------------------------------- ### Unwrap Error Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Returns the Err value or panics if the result is an Ok. ```rust let x: Result = Ok(2); x.unwrap_err(); // panics with `2` ``` ```rust let x: Result = Err("emergency failure"); assert_eq!(x.unwrap_err(), "emergency failure"); ``` -------------------------------- ### Inspect Ok Value Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Executes a closure with a reference to the Ok value without consuming the result. ```rust let x: u8 = "4" .parse::() .inspect(|x| println!("original: {x}")) .map(|x| x.pow(3)) .expect("failed to parse number"); ``` -------------------------------- ### AccessGuardMut::insert Source: https://docs.rs/redb/4.1.0/redb/struct.AccessGuardMut.html Replaces the currently stored value with a new one. ```APIDOC ## pub fn insert<'v>(&mut self, value: impl Borrow>) -> Result<()> ### Description Replace the stored value. ### Parameters - **value** (impl Borrow>) - The new value to store. ### Returns - **Result<()>** - Returns Ok(()) on success, or an error if the operation fails. ``` -------------------------------- ### RepairSession Definition Source: https://docs.rs/redb/4.1.0/redb/struct.RepairSession.html The definition of the RepairSession struct. ```rust pub struct RepairSession { /* private fields */ } ``` -------------------------------- ### ephemeral_savepoint Source: https://docs.rs/redb/4.1.0/redb/struct.WriteTransaction.html Creates a snapshot of the current database state that is automatically freed when the returned Savepoint object is dropped. ```APIDOC ## pub fn ephemeral_savepoint(&self) -> Result ### Description Creates a snapshot of the current database state, which can be used to rollback the database. This savepoint will be freed as soon as the returned `Savepoint` is dropped. ### Returns - `Result`: Returns the savepoint object, or an error if the transaction is dirty. ``` -------------------------------- ### Copy Result Contents Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Copies the contents of an Ok variant for types that implement Copy. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` -------------------------------- ### inspect Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Calls a function with a reference to the contained value if Ok. Returns the original result. ```APIDOC ## pub fn inspect(self, f: F) -> Result ### Description Calls a function with a reference to the contained value if `Ok`. Returns the original result. ``` -------------------------------- ### is_empty() Source: https://docs.rs/redb/4.1.0/redb/struct.MultimapValue.html Checks if the iterator is empty. ```APIDOC ## pub fn is_empty(&self) -> bool ### Description Returns true if the iterator contains no elements. ### Returns - **bool** - True if empty, false otherwise. ``` -------------------------------- ### as_deref_mut Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Converts from Result to Result<&mut ::Target, &mut E>. ```APIDOC ## pub fn as_deref_mut(&mut self) -> Result<&mut ::Target, &mut E> ### Description Converts from `Result` (or `&mut Result`) to `Result<&mut ::Target, &mut E>`. Coerces the `Ok` variant of the original `Result` via `DerefMut` and returns the new `Result`. ``` -------------------------------- ### Table mutation and access methods Source: https://docs.rs/redb/4.1.0/redb/struct.Table.html Methods for modifying table contents, including insertion, removal, and conditional extraction. ```rust pub fn get_mut<'k>( &mut self, key: impl Borrow>, ) -> Result>> ``` ```rust pub fn pop_first( &mut self, ) -> Result, AccessGuard<'_, V>)>> ``` ```rust pub fn pop_last( &mut self, ) -> Result, AccessGuard<'_, V>)>> ``` ```rust pub fn extract_if FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool>( &mut self, predicate: F, ) -> Result> ``` ```rust pub fn extract_from_if<'a, KR, F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool>( &mut self, range: impl RangeBounds + 'a, predicate: F, ) -> Result> where KR: Borrow> + 'a, ``` ```rust pub fn retain FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool>( &mut self, predicate: F, ) -> Result ``` ```rust pub fn retain_in<'a, KR, F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool>( &mut self, range: impl RangeBounds + 'a, predicate: F, ) -> Result where KR: Borrow> + 'a, ``` ```rust pub fn insert<'k, 'v>( &mut self, key: impl Borrow>, value: impl Borrow>, ) -> Result>> ``` ```rust pub fn remove<'a>( &mut self, key: impl Borrow>, ) -> Result>> ``` ```rust pub fn insert_reserve<'a>( &mut self, key: impl Borrow>, value_length: usize, ) -> Result> ``` -------------------------------- ### ReadableDatabase Trait Definition Source: https://docs.rs/redb/4.1.0/redb/trait.ReadableDatabase.html The core trait definition for database readability, requiring implementation of transaction initiation and cache statistics retrieval. ```rust pub trait ReadableDatabase { // Required methods fn begin_read(&self) -> Result; fn cache_stats(&self) -> CacheStats; } ``` -------------------------------- ### as_deref Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Converts from Result to Result<&::Target, &E>. ```APIDOC ## pub fn as_deref(&self) -> Result<&::Target, &E> ### Description Converts from `Result` (or `&Result`) to `Result<&::Target, &E>`. Coerces the `Ok` variant of the original `Result` via `Deref` and returns the new `Result`. ``` -------------------------------- ### iter Source: https://docs.rs/redb/4.1.0/redb/struct.Table.html Returns an iterator over all elements in the table. ```APIDOC ## fn iter(&self) -> Result> ### Description Returns a double-ended iterator over all elements in the table. ``` -------------------------------- ### Map Result values Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Applies a function to the contained Ok value. ```rust let line = "1\n2\n3\n4\n"; for num in line.lines() { match num.parse::().map(|i| i * 2) { Ok(n) => println!("{n}"), Err(..) => {} } } ``` -------------------------------- ### Unwrap Result Value Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Extracts the Ok value or panics if the result is an Err. ```rust let x: Result = Ok(2); assert_eq!(x.unwrap(), 2); ``` ```rust let x: Result = Err("emergency failure"); x.unwrap(); // panics with `emergency failure` ``` -------------------------------- ### last Source: https://docs.rs/redb/4.1.0/redb/struct.Table.html Retrieves the last key-value pair in the table. ```APIDOC ## fn last(&self) -> Result, AccessGuard<'_, V>)>> ### Description Returns the last key-value pair in the table, if it exists. ``` -------------------------------- ### Check Result with is_err_and Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Checks if a Result is an Err and matches a specific predicate. ```rust use std::io::{Error, ErrorKind}; let x: Result = Err(Error::new(ErrorKind::NotFound, "!")); assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), true); let x: Result = Err(Error::new(ErrorKind::PermissionDenied, "!")); assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false); let x: Result = Ok(123); assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false); let x: Result = Err("ownership".to_string()); assert_eq!(x.as_ref().is_err_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` -------------------------------- ### AccessGuardMut::value Source: https://docs.rs/redb/4.1.0/redb/struct.AccessGuardMut.html Retrieves the currently stored value. ```APIDOC ## pub fn value(&self) -> V::SelfType<'_> ### Description Access the stored value. ### Returns - **V::SelfType<'_>** - The stored value. ``` -------------------------------- ### AccessGuardMutInPlace Definition Source: https://docs.rs/redb/4.1.0/redb/struct.AccessGuardMutInPlace.html The definition of the AccessGuardMutInPlace struct. ```rust pub struct AccessGuardMutInPlace<'a, V: Value + 'static> { /* private fields */ } ``` -------------------------------- ### Map Result to default or function result Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Maps a Result to a value using a default or a fallback function. ```rust let x: Result<_, &str> = Ok("foo"); assert_eq!(x.map_or(42, |v| v.len()), 3); let x: Result<&str, _> = Err("bar"); assert_eq!(x.map_or(42, |v| v.len()), 42); ``` ```rust let k = 21; let x : Result<_, &str> = Ok("foo"); assert_eq!(x.map_or_else(|e| k * 2, |v| v.len()), 3); let x : Result<&str, _> = Err("bar"); assert_eq!(x.map_or_else(|e| k * 2, |v| v.len()), 42); ``` ```rust let x: Result<_, &str> = Ok("foo"); let y: Result<&str, _> = Err("bar"); assert_eq!(x.map_or_default(|x| x.len()), 3); assert_eq!(y.map_or_default(|y| y.len()), 0); ``` -------------------------------- ### TypeName::name Source: https://docs.rs/redb/4.1.0/redb/struct.TypeName.html Retrieves the name associated with the TypeName instance. ```APIDOC ## pub fn name(&self) -> &str ### Description Returns the name associated with this TypeName instance. ``` -------------------------------- ### pub fn range<'a, KR>(&self, range: impl RangeBounds) -> Result> Source: https://docs.rs/redb/4.1.0/redb/struct.ReadOnlyTable.html Returns an iterator over a range of elements in the table. The iterator is reference counted and keeps the transaction alive until dropped. ```APIDOC ## pub fn range<'a, KR>(&self, range: impl RangeBounds) -> Result> ### Description Returns an iterator over a range of elements in the table. The iterator is reference counted and keeps the transaction alive until dropped. ``` -------------------------------- ### Into Error Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Extracts the Err value without risk of panicking, intended for infallible results. ```rust fn only_bad_news() -> Result { Err("Oops, it failed".into()) } let error: String = only_bad_news().into_err(); println!("{error}"); ``` -------------------------------- ### Transpose Result and Option Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Converts a Result of an Option into an Option of a Result. ```rust #[derive(Debug, Eq, PartialEq)] struct SomeErr; let x: Result, SomeErr> = Ok(Some(5)); let y: Option> = Some(Ok(5)); assert_eq!(x.transpose(), y); ``` -------------------------------- ### Builder::set_repair_callback Source: https://docs.rs/redb/4.1.0/redb/struct.Builder.html Sets a callback to be invoked if the database file requires repair. ```APIDOC ## pub fn set_repair_callback(&mut self, callback: impl Fn(&mut RepairSession) + 'static) -> &mut Self ### Description Set a callback which will be invoked periodically in the event that the database file needs to be repaired. The RepairSession argument can be used to control the repair process. ``` -------------------------------- ### Clone Result Contents Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Clones the contents of an Ok variant for types that implement Clone. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` -------------------------------- ### MultimapTableDefinition Struct Definition Source: https://docs.rs/redb/4.1.0/redb/struct.MultimapTableDefinition.html The primary structure definition for MultimapTableDefinition. ```rust pub struct MultimapTableDefinition<'a, K: Key + 'static, V: Key + 'static> { /* private fields */ } ``` -------------------------------- ### Table struct definition Source: https://docs.rs/redb/4.1.0/redb/struct.Table.html The primary structure for interacting with key-value data in redb. ```rust pub struct Table<'txn, K: Key + 'static, V: Value + 'static> { /* private fields */ } ``` -------------------------------- ### Key Trait Definition Source: https://docs.rs/redb/4.1.0/redb/trait.Key.html The core trait definition requiring a compare method that returns an Ordering. ```rust pub trait Key: Value { // Required method fn compare(data1: &[u8], data2: &[u8]) -> Ordering; } ``` -------------------------------- ### Define CacheStats struct Source: https://docs.rs/redb/4.1.0/redb/struct.CacheStats.html The definition of the CacheStats struct. ```rust pub struct CacheStats { /* private fields */ } ``` -------------------------------- ### Convert Result to Option Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Converts Result to Option, discarding the error or success value respectively. ```rust let x: Result = Ok(2); assert_eq!(x.ok(), Some(2)); let x: Result = Err("Nothing here"); assert_eq!(x.ok(), None); ``` ```rust let x: Result = Ok(2); assert_eq!(x.err(), None); let x: Result = Err("Nothing here"); assert_eq!(x.err(), Some("Nothing here")); ``` -------------------------------- ### AccessGuard Struct Definition Source: https://docs.rs/redb/4.1.0/redb/struct.AccessGuard.html The definition of the AccessGuard structure, which manages scoped access to database values. ```rust pub struct AccessGuard<'a, V: Value + 'static> { /* private fields */ } ``` -------------------------------- ### ReadTransaction Methods Source: https://docs.rs/redb/4.1.0/redb/struct.ReadTransaction.html Methods available on the ReadTransaction struct for interacting with database tables. ```APIDOC ## pub fn open_table(definition: TableDefinition<'_, K, V>) -> Result, TableError> ### Description Opens a typed table for reading. ## pub fn open_untyped_table(handle: impl TableHandle) -> Result ### Description Opens a table for reading without enforcing a specific type. ## pub fn open_multimap_table(definition: MultimapTableDefinition<'_, K, V>) -> Result, TableError> ### Description Opens a typed multimap table for reading. ## pub fn open_untyped_multimap_table(handle: impl MultimapTableHandle) -> Result ### Description Opens a multimap table for reading without enforcing a specific type. ## pub fn list_tables() -> Result> ### Description Returns an iterator over all tables in the database. ## pub fn list_multimap_tables() -> Result> ### Description Returns an iterator over all multimap tables in the database. ## pub fn close(self) -> Result<(), TransactionError> ### Description Closes the transaction. This is typically handled automatically when the transaction is dropped, but can be called manually to ensure no outstanding objects remain. ``` -------------------------------- ### range Source: https://docs.rs/redb/4.1.0/redb/struct.Table.html Returns a double-ended iterator over a range of elements in the table. ```APIDOC ## fn range<'a, KR>( &self, range: impl RangeBounds + 'a, ) -> Result> ### Description Returns a double-ended iterator over a range of elements in the table. ``` -------------------------------- ### abort Source: https://docs.rs/redb/4.1.0/redb/struct.WriteTransaction.html Aborts the current transaction. ```APIDOC ## pub fn abort(self) -> Result ### Description Aborts the transaction, rolling back all writes performed during the transaction. ``` -------------------------------- ### TableDefinition Struct Definition Source: https://docs.rs/redb/4.1.0/redb/struct.TableDefinition.html The primary structure definition for TableDefinition, requiring Key and Value trait implementations. ```rust pub struct TableDefinition<'a, K: Key + 'static, V: Value + 'static> { /* private fields */ } ``` -------------------------------- ### Check Result Status Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Methods to inspect whether a Result is Ok or Err. ```rust let x: Result = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result = Err("Some error message"); assert_eq!(x.is_ok(), false); ``` ```rust let x: Result = Ok(2); assert_eq!(x.is_ok_and(|x| x > 1), true); let x: Result = Ok(0); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Err("hey"); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Ok("ownership".to_string()); assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` ```rust let x: Result = Ok(-3); assert_eq!(x.is_err(), false); let x: Result = Err("Some error message"); assert_eq!(x.is_err(), true); ``` -------------------------------- ### rename_table Source: https://docs.rs/redb/4.1.0/redb/struct.WriteTransaction.html Renames an existing table. ```APIDOC ## pub fn rename_table( &self, definition: impl TableHandle, new_name: impl TableHandle, ) -> Result<(), TableError> ### Description Renames the given table to the new name provided. ``` -------------------------------- ### Savepoint Struct Definition Source: https://docs.rs/redb/4.1.0/redb/struct.Savepoint.html The definition of the Savepoint struct. ```rust pub struct Savepoint { /* private fields */ } ``` -------------------------------- ### ReadOnlyMultimapTable methods Source: https://docs.rs/redb/4.1.0/redb/struct.ReadOnlyMultimapTable.html Methods for retrieving values or ranges from a read-only multimap table. ```rust pub fn get<'a>( &self, key: impl Borrow>, ) -> Result> ``` ```rust pub fn range<'a, KR>( &self, range: impl RangeBounds, ) -> Result> where KR: Borrow>, ``` -------------------------------- ### len() Source: https://docs.rs/redb/4.1.0/redb/struct.MultimapValue.html Returns the number of times this iterator will return Some(Ok(_)). Note that the iterator may return Some(Err(_)) more times than the value returned by len(). ```APIDOC ## pub fn len(&self) -> u64 ### Description Returns the number of times this iterator will return `Some(Ok(_))`. ### Returns - **u64** - The count of successful iterations. ``` -------------------------------- ### iter Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Returns an iterator over the possibly contained value. ```APIDOC ## pub fn iter(&self) -> Iter<'_, T> ### Description Returns an iterator over the possibly contained value. The iterator yields one value if the result is `Result::Ok`, otherwise none. ``` -------------------------------- ### commit Source: https://docs.rs/redb/4.1.0/redb/struct.WriteTransaction.html Commits the current transaction. ```APIDOC ## pub fn commit(self) -> Result<(), CommitError> ### Description Commits the transaction, making all writes durable and visible to future transactions. ``` -------------------------------- ### Provide fallback results with or_else Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Calls a closure to compute a fallback result if the current result is Err. This is lazily evaluated. ```rust fn sq(x: u32) -> Result { Ok(x * x) } fn err(x: u32) -> Result { Err(x) } assert_eq!(Ok(2).or_else(sq).or_else(sq), Ok(2)); assert_eq!(Ok(2).or_else(err).or_else(sq), Ok(2)); assert_eq!(Err(3).or_else(sq).or_else(err), Ok(9)); assert_eq!(Err(3).or_else(err).or_else(err), Err(3)); ``` -------------------------------- ### rename_multimap_table Source: https://docs.rs/redb/4.1.0/redb/struct.WriteTransaction.html Renames an existing multimap table. ```APIDOC ## pub fn rename_multimap_table( &self, definition: impl MultimapTableHandle, new_name: impl MultimapTableHandle, ) -> Result<(), TableError> ### Description Renames the given multimap table to the new name provided. ``` -------------------------------- ### cache_stats Source: https://docs.rs/redb/4.1.0/redb/struct.Database.html Retrieves information regarding the usage of the in-memory cache. ```APIDOC ### fn cache_stats(&self) -> CacheStats Returns statistics about the current usage of the in-memory cache. ``` -------------------------------- ### ReadOnlyUntypedTable Definition Source: https://docs.rs/redb/4.1.0/redb/struct.ReadOnlyUntypedTable.html The structure definition for ReadOnlyUntypedTable. ```rust pub struct ReadOnlyUntypedTable { /* private fields */ } ``` -------------------------------- ### WriteTransaction Definition Source: https://docs.rs/redb/4.1.0/redb/struct.WriteTransaction.html The internal structure definition for a read/write transaction in redb. ```rust pub struct WriteTransaction { /* private fields */ } ``` -------------------------------- ### AccessGuard::value Source: https://docs.rs/redb/4.1.0/redb/struct.AccessGuard.html Access the stored value within the database. ```APIDOC ## pub fn value(&self) -> V::SelfType<'_> ### Description Access the stored value associated with the AccessGuard instance. ### Returns - **V::SelfType<'_>** - The stored value. ``` -------------------------------- ### Chain fallible operations with and_then Source: https://docs.rs/redb/4.1.0/redb/type.Result.html Use and_then to chain operations that return a Result. The closure is only executed if the previous result is Ok. ```rust assert_eq!(Ok(2).and_then(sq_then_to_string), Ok(4.to_string())); assert_eq!(Ok(1_000_000).and_then(sq_then_to_string), Err("overflowed")); assert_eq!(Err("not a number").and_then(sq_then_to_string), Err("not a number")); ``` ```rust use std::{io::ErrorKind, path::Path}; // Note: on Windows "/" maps to "C:\" let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified()); assert!(root_modified_time.is_ok()); let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified()); assert!(should_fail.is_err()); assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound); ``` -------------------------------- ### delete_table Source: https://docs.rs/redb/4.1.0/redb/struct.WriteTransaction.html Deletes a table from the database. ```APIDOC ## pub fn delete_table( &self, definition: impl TableHandle, ) -> Result ### Description Deletes the specified table. Returns a boolean indicating whether the table existed prior to deletion. ``` -------------------------------- ### TypeName Definition Source: https://docs.rs/redb/4.1.0/redb/struct.TypeName.html The internal structure of TypeName is private. ```rust pub struct TypeName { /* private fields */ } ```