Struct FileHandle

Source
pub struct FileHandle<U: Ui> { /* private fields */ }
Expand description

A handle to a File widget

This handle acts much like an RwData<File>, but it also includes an Area that can be acted upon alongside the File.

This is the only way you are supposed to read information about the File, in order to display it on Widgets, create Texts, and do all sorts of things. You can, of course, also modify a File from within this struct, but you should be careful to prevent infinite loops, where you modify a File, it gets updated, and then you modify it again after noticing that it has changed.

The main difference between a FileHandle<U> and a Handle<File<U>, U> is that the Handle is capable of acting on selections, but is fixed to just one File, while the FileHandle can automatically point to the current File.

Implementations§

Source§

impl<U: Ui> FileHandle<U>

Source

pub fn read<Ret>( &self, pa: &Pass, f: impl FnOnce(&File<U>, &U::Area) -> Ret, ) -> Ret

Reads from the File and the Area using a Pass

The consistent use of a Pass for the purposes of reading/writing to the values of RwDatas ensures that no panic or invalid borrow happens at runtime, even while working with untrusted code. More importantly, Duat uses these guarantees in order to give the end user a ridiculous amount of freedom in where they can do things, whilst keeping Rust’s number one rule and ensuring thread safety, even with a relatively large amount of shareable state.

§Panics

Panics if there is a mutable borrow of this struct somewhere, which could happen if you use RwData::write_unsafe or RwData::write_unsafe_as from some other place

Source

pub fn write<Ret>( &self, pa: &mut Pass, f: impl FnOnce(&mut File<U>, &U::Area) -> Ret, ) -> Ret

Writes to the File and Area within using a Pass

The consistent use of a Pass for the purposes of reading/writing to the values of RwDatas ensures that no panic or invalid borrow happens at runtime, even while working with untrusted code. More importantly, Duat uses these guarantees in order to give the end user a ridiculous amount of freedom in where they can do things, whilst keeping Rust’s number one rule and ensuring thread safety, even with a relatively large amount of shareable state.

§Panics

Panics if there is any type of borrow of this struct somewhere, which could happen if you use RwData::read_unsafe or RwData::write_unsafe, for example.

Reads a Widget related to this File, alongside its Area, with a Pass

A related Widget is one that was pushed to this File during the OnFileOpen hook.

Gets the RwData and Area of a related widget, with a Pass

A related Widget is one that was pushed to this File during the OnFileOpen hook.

Source

pub fn handle(&self, pa: &Pass) -> Handle<File<U>, U>

Gets a Handle from this FileHandle

Source

pub fn has_changed(&self) -> bool

Wether someone else called write or write_as since the last read or write

Do note that this DOES NOT mean that the value inside has actually been changed, it just means a mutable reference was acquired after the last call to has_changed.

Some types like Text, and traits like Widget offer needs_update methods, you should try to determine what parts to look for changes.

Generally though, you can use this method to gauge that.

Source

pub fn has_swapped(&self) -> bool

Wether the File within has swapped to another

This can only happen when this is a

Source

pub fn ptr_eq<T: ?Sized>(&self, pa: &Pass, other: &RwData<T>) -> bool

Wether the RwData within and another point to the same value

Source

pub fn name(&self, pa: &Pass) -> String

The name of the File in question

Source

pub fn path(&self, pa: &Pass) -> String

The path of the File in question

Source

pub fn set_path(&self, pa: &Pass) -> Option<String>

The path of the File in question, if it was set

Trait Implementations§

Source§

impl<U: Clone + Ui> Clone for FileHandle<U>

Source§

fn clone(&self) -> FileHandle<U>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<U> !Freeze for FileHandle<U>

§

impl<U> !RefUnwindSafe for FileHandle<U>

§

impl<U> !Send for FileHandle<U>

§

impl<U> !Sync for FileHandle<U>

§

impl<U> Unpin for FileHandle<U>
where <U as Ui>::Area: Unpin,

§

impl<U> !UnwindSafe for FileHandle<U>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.