Argdata

Trait Argdata 

Source
pub trait Argdata<'d>: Sync {
Show 14 methods // Required methods fn serialize( &self, writer: &mut dyn Write, fd_map: Option<&mut dyn FdMapping>, ) -> Result<()>; fn serialized_length(&self) -> usize; // Provided methods fn read<'a>(&'a self) -> Result<Value<'a, 'd>, ReadError> where 'd: 'a { ... } fn get_type(&self) -> Result<Type, ReadError> { ... } fn read_null(&self) -> Result<(), NotRead> { ... } fn read_binary(&self) -> Result<&'d [u8], NotRead> { ... } fn read_bool(&self) -> Result<bool, NotRead> { ... } fn read_encoded_fd<'a>( &'a self, ) -> Result<EncodedFd<&'a dyn ConvertFd>, NotRead> where 'd: 'a { ... } fn read_float(&self) -> Result<f64, NotRead> { ... } fn read_int_value(&self) -> Result<IntValue<'d>, NotRead> { ... } fn read_map<'a>(&'a self) -> Result<MapIterator<'a, 'd>, NotRead> where 'd: 'a { ... } fn read_seq<'a>(&'a self) -> Result<SeqIterator<'a, 'd>, NotRead> where 'd: 'a { ... } fn read_str_value(&self) -> Result<StrValue<'d>, NotRead> { ... } fn read_timestamp(&self) -> Result<Timespec, NotRead> { ... }
}
Expand description

An argdata value.

Note for implementers of this trait: Although all read methods have provided implementations, they are implemented in terms of eachother. You either need to provide:

  • the read() method, or
  • the get_type() method and implementations of all read_*() methods.

Do the latter if read() would do anything non-trivial, to keep things efficient.

get_type() and read_*() need to be consistent, which means that read_$TYPE() for the type returned by get_type() may not return an Err(NotRead::NoFit). Otherwise, read() will panic.

Required Methods§

Source

fn serialize( &self, writer: &mut dyn Write, fd_map: Option<&mut dyn FdMapping>, ) -> Result<()>

Serialize the argdata to the given writer.

Exactly self.serialized_bytes() bytes are written to the writer, if no error occurs.

File descriptors are mapped using fd_map. If it is None, encoded file descriptors will be kept as is, and actual file descriptors will be encoded as -1 (invalid).

Source

fn serialized_length(&self) -> usize

The number of bytes that self.serialize() will write.

Provided Methods§

Source

fn read<'a>(&'a self) -> Result<Value<'a, 'd>, ReadError>
where 'd: 'a,

Read the value.

Source

fn get_type(&self) -> Result<Type, ReadError>

Read the type of the value.

Source

fn read_null(&self) -> Result<(), NotRead>

Check if the value is null.

Source

fn read_binary(&self) -> Result<&'d [u8], NotRead>

Check if the value is a binary blob, and read it if it is.

Source

fn read_bool(&self) -> Result<bool, NotRead>

Check if the value is a boolean, and read it if it is.

Source

fn read_encoded_fd<'a>( &'a self, ) -> Result<EncodedFd<&'a dyn ConvertFd>, NotRead>
where 'd: 'a,

Check if the value is a file descriptor, and return it if it is.

Even though this function succeeds (returns an Ok()), converting the returned EncodedFd to an Fd might still fail.

Note: You probably want to use read_fd instead.

Source

fn read_float(&self) -> Result<f64, NotRead>

Check if the value is a float, and read it if it is.

Source

fn read_int_value(&self) -> Result<IntValue<'d>, NotRead>

Check if the value is an integer, and read it if it is.

Note: You might want to use read_int instead to directly get a primitive type like i32 or u64.

Source

fn read_map<'a>(&'a self) -> Result<MapIterator<'a, 'd>, NotRead>
where 'd: 'a,

Check if the value is a map, and get an iterator over it if it is.

Source

fn read_seq<'a>(&'a self) -> Result<SeqIterator<'a, 'd>, NotRead>
where 'd: 'a,

Check if the value is a seq, and get an iterator over it if it is.

Source

fn read_str_value(&self) -> Result<StrValue<'d>, NotRead>

Check if the value is a string, and read it if it is.

Note: You probably want to use read_str instead to directly get a &str.

Source

fn read_timestamp(&self) -> Result<Timespec, NotRead>

Check if the value is a timestamp, and read it if it is.

Trait Implementations§

Source§

impl<'a, 'd> Debug for dyn Argdata<'d> + 'a

Source§

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

Formats the value using the given formatter. Read more

Implementors§

Source§

impl<'d> Argdata<'d> for Fd

Source§

impl<'d> Argdata<'d> for InvalidFd

Source§

impl<'d> Argdata<'d> for BigInt<'d>

Source§

impl<'d> Argdata<'d> for Binary<'d>

Source§

impl<'d> Argdata<'d> for Bool

Source§

impl<'d> Argdata<'d> for Float

Source§

impl<'d> Argdata<'d> for Null

Source§

impl<'d> Argdata<'d> for Str<'d>

Source§

impl<'d> Argdata<'d> for Timestamp

Source§

impl<'d, F: ConvertFd> Argdata<'d> for EncodedArgdata<'d, F>

Source§

impl<'d, T> Argdata<'d> for Int<T>
where T: Copy + Sync, IntValue<'static>: From<T>,

Source§

impl<'d, T> Argdata<'d> for Map<'d, T>
where T: MapContainer, <T as MapContainer>::Key: Argdata<'d>, <T as MapContainer>::Value: Argdata<'d>,

Source§

impl<'d, T> Argdata<'d> for Seq<'d, T>
where T: Container, <T as Container>::Item: Argdata<'d>,

Source§

impl<'d, T: ConvertFd> Argdata<'d> for EncodedFd<T>