Struct xplm::data::borrowed::DataRef

source ·
pub struct DataRef<T: ?Sized, A = ReadOnly> { /* private fields */ }
Expand description

A dataref created by X-Plane or another plugin

T is the data type stored in the dataref.

A is the access level (ReadOnly or ReadWrite)

Implementations§

source§

impl<T: DataType + ?Sized> DataRef<T, ReadOnly>

source

pub fn find(name: &str) -> Result<Self, FindError>

Finds a readable dataref by its name

Returns an error if the dataref does not exist or has the wrong type

Examples found in repository?
examples/dataref.rs (line 42)
40
41
42
43
44
45
46
47
48
49
50
51
    fn start() -> Result<Self, Self::Error> {
        let plugin = DataRefPlugin {
            has_joystick: DataRef::find("sim/joystick/has_joystick")?,
            earth_mu: DataRef::find("sim/physics/earth_mu")?,
            date: DataRef::find("sim/time/local_date_days")?.writeable()?,
            sim_build_string: DataRef::find("sim/version/sim_build_string")?,
            latitude: DataRef::find("sim/flightmodel/position/latitude")?,
            joystick_axis_values: DataRef::find("sim/joystick/joystick_axis_values")?,
            battery_on: DataRef::find("sim/cockpit2/electrical/battery_on")?.writeable()?,
        };
        Ok(plugin)
    }
source

pub fn writeable(self) -> Result<DataRef<T, ReadWrite>, FindError>

Makes this dataref writable

Returns an error if the dataref cannot be written.

Examples found in repository?
examples/dataref.rs (line 44)
40
41
42
43
44
45
46
47
48
49
50
51
    fn start() -> Result<Self, Self::Error> {
        let plugin = DataRefPlugin {
            has_joystick: DataRef::find("sim/joystick/has_joystick")?,
            earth_mu: DataRef::find("sim/physics/earth_mu")?,
            date: DataRef::find("sim/time/local_date_days")?.writeable()?,
            sim_build_string: DataRef::find("sim/version/sim_build_string")?,
            latitude: DataRef::find("sim/flightmodel/position/latitude")?,
            joystick_axis_values: DataRef::find("sim/joystick/joystick_axis_values")?,
            battery_on: DataRef::find("sim/cockpit2/electrical/battery_on")?.writeable()?,
        };
        Ok(plugin)
    }

Trait Implementations§

source§

impl<A> ArrayRead<[f32]> for DataRef<[f32], A>

source§

fn get(&self, dest: &mut [f32]) -> usize

Reads values Read more
source§

fn len(&self) -> usize

Returns the length of the data array
source§

fn as_vec(&self) -> Vec<T::Element>
where T::Element: Default + Clone,

Returns all values in this accessor as a Vec
source§

impl<A> ArrayRead<[i32]> for DataRef<[i32], A>

source§

fn get(&self, dest: &mut [i32]) -> usize

Reads values Read more
source§

fn len(&self) -> usize

Returns the length of the data array
source§

fn as_vec(&self) -> Vec<T::Element>
where T::Element: Default + Clone,

Returns all values in this accessor as a Vec
source§

impl<A> ArrayRead<[i8]> for DataRef<[i8], A>

source§

fn get(&self, dest: &mut [i8]) -> usize

Reads values Read more
source§

fn len(&self) -> usize

Returns the length of the data array
source§

fn as_vec(&self) -> Vec<T::Element>
where T::Element: Default + Clone,

Returns all values in this accessor as a Vec
source§

impl<A> ArrayRead<[u32]> for DataRef<[u32], A>

source§

fn get(&self, dest: &mut [u32]) -> usize

Reads values Read more
source§

fn len(&self) -> usize

Returns the length of the data array
source§

fn as_vec(&self) -> Vec<T::Element>
where T::Element: Default + Clone,

Returns all values in this accessor as a Vec
source§

impl<A> ArrayRead<[u8]> for DataRef<[u8], A>

source§

fn get(&self, dest: &mut [u8]) -> usize

Reads values Read more
source§

fn len(&self) -> usize

Returns the length of the data array
source§

fn as_vec(&self) -> Vec<T::Element>
where T::Element: Default + Clone,

Returns all values in this accessor as a Vec
source§

impl ArrayReadWrite<[f32]> for DataRef<[f32], ReadWrite>

source§

fn set(&mut self, values: &[f32])

Writes values Read more
source§

impl ArrayReadWrite<[i32]> for DataRef<[i32], ReadWrite>

source§

fn set(&mut self, values: &[i32])

Writes values Read more
source§

impl ArrayReadWrite<[i8]> for DataRef<[i8], ReadWrite>

source§

fn set(&mut self, values: &[i8])

Writes values Read more
source§

impl ArrayReadWrite<[u32]> for DataRef<[u32], ReadWrite>

source§

fn set(&mut self, values: &[u32])

Writes values Read more
source§

impl ArrayReadWrite<[u8]> for DataRef<[u8], ReadWrite>

source§

fn set(&mut self, values: &[u8])

Writes values Read more
source§

impl<A> DataRead<bool> for DataRef<bool, A>

source§

fn get(&self) -> bool

Reads a value
source§

impl<A> DataRead<f32> for DataRef<f32, A>

source§

fn get(&self) -> f32

Reads a value
source§

impl<A> DataRead<f64> for DataRef<f64, A>

source§

fn get(&self) -> f64

Reads a value
source§

impl<A> DataRead<i16> for DataRef<i16, A>

source§

fn get(&self) -> i16

Reads a value
source§

impl<A> DataRead<i32> for DataRef<i32, A>

source§

fn get(&self) -> i32

Reads a value
source§

impl<A> DataRead<i8> for DataRef<i8, A>

source§

fn get(&self) -> i8

Reads a value
source§

impl<A> DataRead<u16> for DataRef<u16, A>

source§

fn get(&self) -> u16

Reads a value
source§

impl<A> DataRead<u32> for DataRef<u32, A>

source§

fn get(&self) -> u32

Reads a value
source§

impl<A> DataRead<u8> for DataRef<u8, A>

source§

fn get(&self) -> u8

Reads a value
source§

impl DataReadWrite<bool> for DataRef<bool, ReadWrite>

source§

fn set(&mut self, value: bool)

Writes a value
source§

impl DataReadWrite<f32> for DataRef<f32, ReadWrite>

source§

fn set(&mut self, value: f32)

Writes a value
source§

impl DataReadWrite<f64> for DataRef<f64, ReadWrite>

source§

fn set(&mut self, value: f64)

Writes a value
source§

impl DataReadWrite<i16> for DataRef<i16, ReadWrite>

source§

fn set(&mut self, value: i16)

Writes a value
source§

impl DataReadWrite<i32> for DataRef<i32, ReadWrite>

source§

fn set(&mut self, value: i32)

Writes a value
source§

impl DataReadWrite<i8> for DataRef<i8, ReadWrite>

source§

fn set(&mut self, value: i8)

Writes a value
source§

impl DataReadWrite<u16> for DataRef<u16, ReadWrite>

source§

fn set(&mut self, value: u16)

Writes a value
source§

impl DataReadWrite<u32> for DataRef<u32, ReadWrite>

source§

fn set(&mut self, value: u32)

Writes a value
source§

impl DataReadWrite<u8> for DataRef<u8, ReadWrite>

source§

fn set(&mut self, value: u8)

Writes a value

Auto Trait Implementations§

§

impl<T, A> Freeze for DataRef<T, A>
where T: ?Sized,

§

impl<T, A> RefUnwindSafe for DataRef<T, A>

§

impl<T, A = ReadOnly> !Send for DataRef<T, A>

§

impl<T, A = ReadOnly> !Sync for DataRef<T, A>

§

impl<T, A> Unpin for DataRef<T, A>
where T: Unpin + ?Sized, A: Unpin,

§

impl<T, A> UnwindSafe for DataRef<T, A>
where T: UnwindSafe + ?Sized, A: UnwindSafe,

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> StringRead for T
where T: ArrayRead<[u8]>,

source§

fn get_to_string(&self, out: &mut String) -> Result<(), FromUtf8Error>

Reads the value of this dataref and appends it to the provided string Read more
source§

fn get_as_string(&self) -> Result<String, FromUtf8Error>

Reads the value of this dataref as a string and returns it
source§

impl<T> StringReadWrite for T
where T: ArrayReadWrite<[u8]>,

source§

fn set_as_string(&mut self, value: &str) -> Result<(), NulError>

Sets the value of this dataref from a string Read more
source§

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

§

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

§

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.