pub struct SharedRow(Rc<RefCell<Row>>);
Expand description
A thread-local row, which can be borrowed and returned.
§Example
Use this type instead of creating a new row:
use mz_repr::SharedRow;
let binding = SharedRow::get();
let mut row_builder = binding.borrow_mut();
This allows us to reuse an existing row allocation instead of creating a new one or retaining an allocation locally. Additionally, we can observe the size of the local row in a central place and potentially reallocate to reduce memory needs.
§Panic
SharedRow::get
panics when trying to obtain multiple references to the shared row.
Tuple Fields§
§0: Rc<RefCell<Row>>
Implementations§
Methods from Deref<Target = RefCell<Row>>§
1.24.0 · sourcepub fn replace(&self, t: T) -> T
pub fn replace(&self, t: T) -> T
Replaces the wrapped value with a new one, returning the old value, without deinitializing either one.
This function corresponds to std::mem::replace
.
§Panics
Panics if the value is currently borrowed.
§Examples
use std::cell::RefCell;
let cell = RefCell::new(5);
let old_value = cell.replace(6);
assert_eq!(old_value, 5);
assert_eq!(cell, RefCell::new(6));
1.35.0 · sourcepub fn replace_with<F>(&self, f: F) -> T
pub fn replace_with<F>(&self, f: F) -> T
Replaces the wrapped value with a new one computed from f
, returning
the old value, without deinitializing either one.
§Panics
Panics if the value is currently borrowed.
§Examples
use std::cell::RefCell;
let cell = RefCell::new(5);
let old_value = cell.replace_with(|&mut old| old + 1);
assert_eq!(old_value, 5);
assert_eq!(cell, RefCell::new(6));
1.24.0 · sourcepub fn swap(&self, other: &RefCell<T>)
pub fn swap(&self, other: &RefCell<T>)
Swaps the wrapped value of self
with the wrapped value of other
,
without deinitializing either one.
This function corresponds to std::mem::swap
.
§Panics
Panics if the value in either RefCell
is currently borrowed, or
if self
and other
point to the same RefCell
.
§Examples
use std::cell::RefCell;
let c = RefCell::new(5);
let d = RefCell::new(6);
c.swap(&d);
assert_eq!(c, RefCell::new(6));
assert_eq!(d, RefCell::new(5));
1.0.0 · sourcepub fn borrow(&self) -> Ref<'_, T>
pub fn borrow(&self) -> Ref<'_, T>
Immutably borrows the wrapped value.
The borrow lasts until the returned Ref
exits scope. Multiple
immutable borrows can be taken out at the same time.
§Panics
Panics if the value is currently mutably borrowed. For a non-panicking variant, use
try_borrow
.
§Examples
use std::cell::RefCell;
let c = RefCell::new(5);
let borrowed_five = c.borrow();
let borrowed_five2 = c.borrow();
An example of panic:
use std::cell::RefCell;
let c = RefCell::new(5);
let m = c.borrow_mut();
let b = c.borrow(); // this causes a panic
1.13.0 · sourcepub fn try_borrow(&self) -> Result<Ref<'_, T>, BorrowError>
pub fn try_borrow(&self) -> Result<Ref<'_, T>, BorrowError>
Immutably borrows the wrapped value, returning an error if the value is currently mutably borrowed.
The borrow lasts until the returned Ref
exits scope. Multiple immutable borrows can be
taken out at the same time.
This is the non-panicking variant of borrow
.
§Examples
use std::cell::RefCell;
let c = RefCell::new(5);
{
let m = c.borrow_mut();
assert!(c.try_borrow().is_err());
}
{
let m = c.borrow();
assert!(c.try_borrow().is_ok());
}
1.0.0 · sourcepub fn borrow_mut(&self) -> RefMut<'_, T>
pub fn borrow_mut(&self) -> RefMut<'_, T>
Mutably borrows the wrapped value.
The borrow lasts until the returned RefMut
or all RefMut
s derived
from it exit scope. The value cannot be borrowed while this borrow is
active.
§Panics
Panics if the value is currently borrowed. For a non-panicking variant, use
try_borrow_mut
.
§Examples
use std::cell::RefCell;
let c = RefCell::new("hello".to_owned());
*c.borrow_mut() = "bonjour".to_owned();
assert_eq!(&*c.borrow(), "bonjour");
An example of panic:
use std::cell::RefCell;
let c = RefCell::new(5);
let m = c.borrow();
let b = c.borrow_mut(); // this causes a panic
1.13.0 · sourcepub fn try_borrow_mut(&self) -> Result<RefMut<'_, T>, BorrowMutError>
pub fn try_borrow_mut(&self) -> Result<RefMut<'_, T>, BorrowMutError>
Mutably borrows the wrapped value, returning an error if the value is currently borrowed.
The borrow lasts until the returned RefMut
or all RefMut
s derived
from it exit scope. The value cannot be borrowed while this borrow is
active.
This is the non-panicking variant of borrow_mut
.
§Examples
use std::cell::RefCell;
let c = RefCell::new(5);
{
let m = c.borrow();
assert!(c.try_borrow_mut().is_err());
}
assert!(c.try_borrow_mut().is_ok());
1.12.0 · sourcepub fn as_ptr(&self) -> *mut T
pub fn as_ptr(&self) -> *mut T
Returns a raw pointer to the underlying data in this cell.
§Examples
use std::cell::RefCell;
let c = RefCell::new(5);
let ptr = c.as_ptr();
1.37.0 · sourcepub unsafe fn try_borrow_unguarded(&self) -> Result<&T, BorrowError>
pub unsafe fn try_borrow_unguarded(&self) -> Result<&T, BorrowError>
Immutably borrows the wrapped value, returning an error if the value is currently mutably borrowed.
§Safety
Unlike RefCell::borrow
, this method is unsafe because it does not
return a Ref
, thus leaving the borrow flag untouched. Mutably
borrowing the RefCell
while the reference returned by this method
is alive is undefined behaviour.
§Examples
use std::cell::RefCell;
let c = RefCell::new(5);
{
let m = c.borrow_mut();
assert!(unsafe { c.try_borrow_unguarded() }.is_err());
}
{
let m = c.borrow();
assert!(unsafe { c.try_borrow_unguarded() }.is_ok());
}
Trait Implementations§
Auto Trait Implementations§
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
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
source§impl<T, U> OverrideFrom<Option<&T>> for Uwhere
U: OverrideFrom<T>,
impl<T, U> OverrideFrom<Option<&T>> for Uwhere
U: OverrideFrom<T>,
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
source§fn into_rust(self) -> Result<R, TryFromProtoError>
fn into_rust(self) -> Result<R, TryFromProtoError>
RustType::from_proto
.source§fn from_rust(rust: &R) -> P
fn from_rust(rust: &R) -> P
RustType::into_proto
.source§impl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
impl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
source§fn plus_equals(&mut self, rhs: &&'a S)
fn plus_equals(&mut self, rhs: &&'a S)
std::ops::AddAssign
, for types that do not implement AddAssign
.