pub struct UnsafePinned<T>where
T: ?Sized,{ /* private fields */ }unsafe_pinned)Expand description
This type provides a way to entirely opt-out of typical aliasing rules;
specifically, &mut UnsafePinned<T> is not guaranteed to be a unique pointer.
This also subsumes the effects of UnsafeCell, i.e., &UnsafePinned<T> may point to data
that is being mutated.
However, even if you define your type like pub struct Wrapper(UnsafePinned<...>), it is still
very risky to have an &mut Wrapper that aliases anything else. Many functions that work
generically on &mut T assume that the memory that stores T is uniquely owned (such as
mem::swap). In other words, while having aliasing with &mut Wrapper is not immediate
Undefined Behavior, it is still unsound to expose such a mutable reference to code you do not
control! Techniques such as pinning via Pin are needed to ensure soundness.
Similar to UnsafeCell, UnsafePinned will not usually show up in
the public API of a library. It is an internal implementation detail of libraries that need to
support aliasing mutable references.
This type blocks niches the same way UnsafeCell does.
Implementationsยง
Sourceยงimpl<T> UnsafePinned<T>
impl<T> UnsafePinned<T>
Sourcepub const fn new(value: T) -> UnsafePinned<T>
๐ฌThis is a nightly-only experimental API. (unsafe_pinned)
pub const fn new(value: T) -> UnsafePinned<T>
unsafe_pinned)Constructs a new instance of UnsafePinned which will wrap the specified value.
All access to the inner value through &UnsafePinned<T> or &mut UnsafePinned<T> or
Pin<&mut UnsafePinned<T>> requires unsafe code.
Sourcepub const fn into_inner(self) -> T
๐ฌThis is a nightly-only experimental API. (unsafe_pinned)
pub const fn into_inner(self) -> T
unsafe_pinned)Unwraps the value, consuming this UnsafePinned.
Sourceยงimpl<T> UnsafePinned<T>where
T: ?Sized,
impl<T> UnsafePinned<T>where
T: ?Sized,
Sourcepub const fn get_mut_pinned(self: Pin<&mut UnsafePinned<T>>) -> *mut T
๐ฌThis is a nightly-only experimental API. (unsafe_pinned)
pub const fn get_mut_pinned(self: Pin<&mut UnsafePinned<T>>) -> *mut T
unsafe_pinned)Get read-write access to the contents of a pinned UnsafePinned.
Sourcepub const fn get_mut_unchecked(&mut self) -> *mut T
๐ฌThis is a nightly-only experimental API. (unsafe_pinned)
pub const fn get_mut_unchecked(&mut self) -> *mut T
unsafe_pinned)Get read-write access to the contents of an UnsafePinned.
You should usually be using get_mut_pinned instead to explicitly track the fact that this
memory is โpinnedโ due to there being aliases.
Sourcepub const fn get(&self) -> *mut T
๐ฌThis is a nightly-only experimental API. (unsafe_pinned)
pub const fn get(&self) -> *mut T
unsafe_pinned)Get mutable access to the contents of a shared UnsafePinned.
This can be cast to a pointer of any kind. When creating references, you must uphold the
aliasing rules; see UnsafeCell for more discussion and caveats.
#![feature(unsafe_pinned)]
use std::pin::UnsafePinned;
unsafe {
let mut x = UnsafePinned::new(0);
let ptr = x.get();
x.get_mut_unchecked().write(1);
assert_eq!(ptr.read(), 1);
}Sourcepub const fn raw_get(this: *const UnsafePinned<T>) -> *mut T
๐ฌThis is a nightly-only experimental API. (unsafe_pinned)
pub const fn raw_get(this: *const UnsafePinned<T>) -> *mut T
unsafe_pinned)Gets an immutable pointer to the wrapped value.
The difference from get is that this function accepts a raw pointer, which is useful to
avoid the creation of temporary references.
Sourcepub const fn raw_get_mut(this: *mut UnsafePinned<T>) -> *mut T
๐ฌThis is a nightly-only experimental API. (unsafe_pinned)
pub const fn raw_get_mut(this: *mut UnsafePinned<T>) -> *mut T
unsafe_pinned)Gets a mutable pointer to the wrapped value.
The difference from get_mut_pinned and get_mut_unchecked is that this function
accepts a raw pointer, which is useful to avoid the creation of temporary references.
Trait Implementationsยง
Sourceยงimpl<T> Debug for UnsafePinned<T>where
T: ?Sized,
impl<T> Debug for UnsafePinned<T>where
T: ?Sized,
Sourceยงimpl<T> Default for UnsafePinned<T>where
T: Default,
impl<T> Default for UnsafePinned<T>where
T: Default,
Sourceยงfn default() -> UnsafePinned<T>
fn default() -> UnsafePinned<T>
Creates an UnsafePinned, with the Default value for T.
Sourceยงimpl<T> From<T> for UnsafePinned<T>
impl<T> From<T> for UnsafePinned<T>
Sourceยงfn from(value: T) -> UnsafePinned<T>
fn from(value: T) -> UnsafePinned<T>
Creates a new UnsafePinned<T> containing the given value.
impl<T, U> CoerceUnsized<UnsafePinned<U>> for UnsafePinned<T>where
T: CoerceUnsized<U>,
impl<T, U> DispatchFromDyn<UnsafePinned<U>> for UnsafePinned<T>where
T: DispatchFromDyn<U>,
impl<T> Sync for UnsafePinned<T>
impl<T> !Unpin for UnsafePinned<T>where
T: ?Sized,
When this type is used, that almost certainly means safe APIs need to use pinning to avoid the
aliases from becoming invalidated. Therefore letโs mark this as !Unpin. You can always opt
back in to Unpin with an impl block, provided your API is still sound while unpinned.
Auto Trait Implementationsยง
impl<T> !Freeze for UnsafePinned<T>
impl<T> !RefUnwindSafe for UnsafePinned<T>
impl<T> Send for UnsafePinned<T>
impl<T> UnwindSafe for UnsafePinned<T>where
T: UnwindSafe + ?Sized,
Blanket Implementationsยง
Sourceยงimpl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Sourceยงimpl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Sourceยงimpl<T> Instrument for T
impl<T> Instrument for T
Sourceยงfn instrument(self, span: Span) -> Instrumented<Self> โ
fn instrument(self, span: Span) -> Instrumented<Self> โ
Sourceยงfn in_current_span(self) -> Instrumented<Self> โ
fn in_current_span(self) -> Instrumented<Self> โ
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self> โ
fn into_either(self, into_left: bool) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงimpl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Sourceยงfn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
ยงExample
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Sourceยงfn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Sourceยงfn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Sourceยงfn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Sourceยงfn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Sourceยงfn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Sourceยงfn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Sourceยงfn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Sourceยงfn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Sourceยงfn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
ยงExample
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Sourceยงfn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Sourceยงfn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Sourceยงfn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Sourceยงfn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Sourceยงfn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Sourceยงfn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Sourceยงfn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Sourceยงfn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Sourceยงfn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Sourceยงfn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Sourceยงfn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
ยงExample
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Sourceยงfn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Sourceยงfn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
ยงExample
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Sourceยงfn clear(&self) -> Painted<&T>
๐Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Sourceยงfn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
ยงExample
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);