pub struct BufferBuilderAsync { /* private fields */ }
Available on
async
only.Expand description
Builder for the creation of a buffer.
Implementations§
Source§impl BufferBuilderAsync
impl BufferBuilderAsync
Sourcepub fn new(name: &str) -> Self
pub fn new(name: &str) -> Self
Create a new buffer builder that will create a buffer with an async input callback.
§Arguments
name
- The name of the new buffer. Needs to be unique across a plugin, otherwise the buffer creation will fail.
Returns a Buffer if one has been created, otherwise an empty Error.
§Panics
Panics if the method is not called from the main Weechat thread.
§Example
fn input_cb(buffer: BufferHandle, input: String) -> LocalBoxFuture<'static, ()> {
async move {
let buffer = buffer.upgrade().unwrap();
buffer.print(&input);
}.boxed_local()
}
let buffer_handle = BufferBuilderAsync::new("test_buffer")
.input_callback(input_cb)
.close_callback(|weechat: &Weechat, buffer: &Buffer| {
Ok(())
})
.build()
.expect("Can't create new buffer");
let buffer = buffer_handle
.upgrade()
.expect("Can't upgrade newly created buffer");
buffer.enable_nicklist();
buffer.print("Hello world");
Sourcepub fn input_callback(self, callback: impl BufferInputCallbackAsync) -> Self
pub fn input_callback(self, callback: impl BufferInputCallbackAsync) -> Self
Set the buffer input callback.
§Arguments
callback
- An async function that will be called once a user inputs data into the buffer input line.
Sourcepub fn close_callback(
self,
callback: impl BufferCloseCallback + 'static,
) -> Self
pub fn close_callback( self, callback: impl BufferCloseCallback + 'static, ) -> Self
Set the close callback.
§Arguments
callback
- The callback that should be called before a buffer is closed.
Sourcepub fn build(self) -> Result<BufferHandle, ()>
pub fn build(self) -> Result<BufferHandle, ()>
Build the configured buffer.
Auto Trait Implementations§
impl Freeze for BufferBuilderAsync
impl !RefUnwindSafe for BufferBuilderAsync
impl !Send for BufferBuilderAsync
impl !Sync for BufferBuilderAsync
impl Unpin for BufferBuilderAsync
impl !UnwindSafe for BufferBuilderAsync
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