Skip to main content

OwnedRset

Struct OwnedRset 

Source
pub struct OwnedRset { /* private fields */ }
Expand description

A freshly-built record set not yet inserted into a Db. Owns its rec_rset_t until handed to Db::append_rset, at which point ownership is transferred to the containing database.

Implementations§

Source§

impl OwnedRset

Source

pub fn new() -> Self

Examples found in repository?
examples/write_rec.rs (line 12)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let mut db = Db::new();
11
12    let mut rset = OwnedRset::new();
13
14    let mut descriptor = Record::new();
15    descriptor.append_field("%rec", "Book")?;
16    descriptor.append_field("%type", "Year int")?;
17    descriptor.append_field("%mandatory", "Title")?;
18    rset.set_descriptor(descriptor);
19
20    for (title, author, year) in [
21        ("Refactoring", "Martin Fowler", "1999"),
22        ("Domain-Driven Design", "Eric Evans", "2003"),
23        ("Test-Driven Development", "Kent Beck", "2002"),
24    ] {
25        let mut record = Record::new();
26        record.append_field("Title", title)?;
27        record.append_field("Author", author)?;
28        record.append_field("Year", year)?;
29        rset.append_record(record)?;
30    }
31
32    db.append_rset(rset)?;
33    println!("{}", db.to_rec_string()?);
34    Ok(())
35}
Source

pub fn set_descriptor(&mut self, record: Record)

Install record as this rset’s descriptor (the %rec: / %type: / %mandatory: block). Ownership of the record transfers to the rset. Replaces and destroys any prior descriptor.

Examples found in repository?
examples/write_rec.rs (line 18)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let mut db = Db::new();
11
12    let mut rset = OwnedRset::new();
13
14    let mut descriptor = Record::new();
15    descriptor.append_field("%rec", "Book")?;
16    descriptor.append_field("%type", "Year int")?;
17    descriptor.append_field("%mandatory", "Title")?;
18    rset.set_descriptor(descriptor);
19
20    for (title, author, year) in [
21        ("Refactoring", "Martin Fowler", "1999"),
22        ("Domain-Driven Design", "Eric Evans", "2003"),
23        ("Test-Driven Development", "Kent Beck", "2002"),
24    ] {
25        let mut record = Record::new();
26        record.append_field("Title", title)?;
27        record.append_field("Author", author)?;
28        record.append_field("Year", year)?;
29        rset.append_record(record)?;
30    }
31
32    db.append_rset(rset)?;
33    println!("{}", db.to_rec_string()?);
34    Ok(())
35}
Source

pub fn append_record(&mut self, record: Record) -> Result<(), Error>

Examples found in repository?
examples/write_rec.rs (line 29)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let mut db = Db::new();
11
12    let mut rset = OwnedRset::new();
13
14    let mut descriptor = Record::new();
15    descriptor.append_field("%rec", "Book")?;
16    descriptor.append_field("%type", "Year int")?;
17    descriptor.append_field("%mandatory", "Title")?;
18    rset.set_descriptor(descriptor);
19
20    for (title, author, year) in [
21        ("Refactoring", "Martin Fowler", "1999"),
22        ("Domain-Driven Design", "Eric Evans", "2003"),
23        ("Test-Driven Development", "Kent Beck", "2002"),
24    ] {
25        let mut record = Record::new();
26        record.append_field("Title", title)?;
27        record.append_field("Author", author)?;
28        record.append_field("Year", year)?;
29        rset.append_record(record)?;
30    }
31
32    db.append_rset(rset)?;
33    println!("{}", db.to_rec_string()?);
34    Ok(())
35}

Trait Implementations§

Source§

impl Default for OwnedRset

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for OwnedRset

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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> 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, 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.