pub struct Hooks<'a, 'b: 'a> { /* private fields */ }Expand description
hooks 管理器,负责组件内所有 hook 的注册、索引和生命周期。
- 通过
use_hook注册/获取 hook 实例,保证顺序和类型安全。 - 支持 context 注入、首次更新标记等。
- 用户无需手动创建,框架自动管理。
§示例
let mut state = hooks.use_state(|| 0);
let ctx = hooks.use_context::<MyType>();Implementations§
Trait Implementations§
Source§impl<'a> UseContext<'a> for Hooks<'a, '_>
impl<'a> UseContext<'a> for Hooks<'a, '_>
Source§fn use_context<T: Any>(&self) -> Ref<'a, T>
fn use_context<T: Any>(&self) -> Ref<'a, T>
获取全局/局部上下文,实现依赖注入。适合主题、配置、全局状态等场景。
Source§fn use_context_mut<T: Any>(&self) -> RefMut<'a, T>
fn use_context_mut<T: Any>(&self) -> RefMut<'a, T>
获取可变上下文。
Source§impl UseInsertBefore for Hooks<'_, '_>
impl UseInsertBefore for Hooks<'_, '_>
Source§fn use_insert_before(&mut self) -> InsertBeforeHandler
fn use_insert_before(&mut self) -> InsertBeforeHandler
在终端渲染区域前插入内容。
Source§impl UseOnDrop for Hooks<'_, '_>
impl UseOnDrop for Hooks<'_, '_>
Source§fn use_on_drop<F>(&mut self, f: F)
fn use_on_drop<F>(&mut self, f: F)
在组件销毁时执行回调。注意不要在回调中使用State。
Source§impl UsePreviousSize for Hooks<'_, '_>
impl UsePreviousSize for Hooks<'_, '_>
fn use_previous_size(&mut self) -> Rect
Source§impl UseTerminalSize for Hooks<'_, '_>
impl UseTerminalSize for Hooks<'_, '_>
fn use_terminal_size(&mut self) -> (u16, u16)
Auto Trait Implementations§
impl<'a, 'b> Freeze for Hooks<'a, 'b>
impl<'a, 'b> !RefUnwindSafe for Hooks<'a, 'b>
impl<'a, 'b> !Send for Hooks<'a, 'b>
impl<'a, 'b> !Sync for Hooks<'a, 'b>
impl<'a, 'b> Unpin for Hooks<'a, 'b>
impl<'a, 'b> !UnwindSafe for Hooks<'a, 'b>
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> 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>
Converts
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>
Converts
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 more