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>
impl<T: DataType + ?Sized> DataRef<T, ReadOnly>
sourcepub fn find(name: &str) -> Result<Self, FindError>
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)
}
sourcepub fn writeable(self) -> Result<DataRef<T, ReadWrite>, FindError>
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§
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>
impl<T, A> UnwindSafe for DataRef<T, A>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> StringRead for T
impl<T> StringRead for T
source§fn get_to_string(&self, out: &mut String) -> Result<(), FromUtf8Error>
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>
fn get_as_string(&self) -> Result<String, FromUtf8Error>
Reads the value of this dataref as a string and returns it