Enum ResourceEntry

Source
pub enum ResourceEntry<T> {
    Empty,
    Owned(T),
    Borrowed(Arc<RwLock<bool>>, *const T),
}
Expand description

The semantics of component model resources are, pleasingly, roughly compatible with those of Rust references, so we would like to use the more-or-less directly in interfaces generated by hyperlight_component_macro. Less pleasingly, it’s not terribly easy to show the semantic agreement statically.

In particular, if the host calls into the guest and gives it a borrow of a resource, reentrant host function calls that use that borrow need to be able to resolve the original reference and use it in an appropriately scoped manner, but it is not simple to do this, because the core Hyperlight machinery doesn’t offer an easy way to augment the host’s context for the span of time of a guest function call. This may be worth revisiting at some time, but in the meantime, it’s easier to just do it dynamically.

§Safety

Informally: this only creates SharedRead references, so having a bunch of them going at once is fine. Safe Rust in the host can’t use any earlier borrows (potentially invalidating these) until borrow passed into ResourceEntry::lend has expired. Because that borrow outlives the LentResourceGuard, it will not expire until that destructor is called. That destructor ensures that (a) there are no outstanding BorrowedResourceGuards alive (since they would be holding the read side of the RwLock if they were), and that (b) the shared flag has been set to false, so ResourceEntry::borrow will never create another borrow

Variants§

§

Empty

§

Owned(T)

§

Borrowed(Arc<RwLock<bool>>, *const T)

Implementations§

Source§

impl<T> ResourceEntry<T>

Source

pub fn give(x: T) -> ResourceEntry<T>

Source

pub fn lend<'a>(x: &'a T) -> (LentResourceGuard<'a>, ResourceEntry<T>)

Source

pub fn borrow<'a>(&'a self) -> Option<BorrowedResourceGuard<'a, T>>

Source

pub fn take(&mut self) -> Option<T>

Trait Implementations§

Auto Trait Implementations§

§

impl<T> Freeze for ResourceEntry<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for ResourceEntry<T>

§

impl<T> !Sync for ResourceEntry<T>

§

impl<T> Unpin for ResourceEntry<T>
where T: Unpin,

§

impl<T> !UnwindSafe for ResourceEntry<T>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more