ChannelOwnerImpl

Struct ChannelOwnerImpl 

Source
pub struct ChannelOwnerImpl { /* private fields */ }
Expand description

Base implementation of ChannelOwner that can be embedded in protocol objects.

This struct provides the common functionality for all ChannelOwner implementations. Protocol objects (Browser, Page, etc.) should contain this as a field and delegate trait methods to it.

§Example

use playwright_core::channel_owner::{ChannelOwner, ChannelOwnerImpl, ParentOrConnection, DisposeReason};
use playwright_core::channel::Channel;
use playwright_core::connection::ConnectionLike;
use std::sync::Arc;
use std::any::Any;
use serde_json::Value;

pub struct Browser {
    base: ChannelOwnerImpl,
    // ... browser-specific fields
}

impl Browser {
    pub fn new(
        parent: Arc<dyn ChannelOwner>,
        type_name: String,
        guid: Arc<str>,
        initializer: Value,
    ) -> Self {
        let base = ChannelOwnerImpl::new(
            ParentOrConnection::Parent(parent),
            type_name,
            guid,
            initializer,
        );
        Self { base }
    }
}

impl ChannelOwner for Browser {
    fn guid(&self) -> &str { self.base.guid() }
    fn type_name(&self) -> &str { self.base.type_name() }
    fn parent(&self) -> Option<Arc<dyn ChannelOwner>> { self.base.parent() }
    fn connection(&self) -> Arc<dyn ConnectionLike> { self.base.connection() }
    fn initializer(&self) -> &Value { self.base.initializer() }
    fn channel(&self) -> &Channel { self.base.channel() }
    fn dispose(&self, reason: DisposeReason) { self.base.dispose(reason) }
    fn adopt(&self, child: Arc<dyn ChannelOwner>) { self.base.adopt(child) }
    fn add_child(&self, guid: Arc<str>, child: Arc<dyn ChannelOwner>) {
        self.base.add_child(guid, child)
    }
    fn remove_child(&self, guid: &str) { self.base.remove_child(guid) }
    fn on_event(&self, method: &str, params: Value) { self.base.on_event(method, params) }
    fn was_collected(&self) -> bool { self.base.was_collected() }
    fn as_any(&self) -> &dyn Any { self }
}

Implementations§

Source§

impl ChannelOwnerImpl

Source

pub fn new( parent: ParentOrConnection, type_name: String, guid: Arc<str>, initializer: Value, ) -> Self

Creates a new ChannelOwner base implementation.

This constructor:

  1. Extracts the connection from parent or uses provided connection
  2. Creates the channel for RPC communication
  3. Stores the initializer data
  4. Registers itself in the connection (done by caller via Connection::register_object)
  5. Registers itself in parent (done by caller via parent.add_child)
§Arguments
  • parent - Either a parent ChannelOwner or the root Connection
  • type_name - Protocol type name (e.g., “Browser”)
  • guid - Unique GUID from server
  • initializer - Initial state from __create__ message
Source

pub fn guid(&self) -> &str

Returns the unique GUID for this object.

Source

pub fn type_name(&self) -> &str

Returns the protocol type name.

Source

pub fn parent(&self) -> Option<Arc<dyn ChannelOwner>>

Returns the parent object, if any.

Source

pub fn connection(&self) -> Arc<dyn ConnectionLike>

Returns the connection.

Source

pub fn initializer(&self) -> &Value

Returns the initializer JSON.

Source

pub fn channel(&self) -> &Channel

Returns the channel for RPC.

Source

pub fn dispose(&self, reason: DisposeReason)

Disposes this object and all children recursively.

§Arguments
  • reason - Why the object is being disposed
Source

pub fn adopt(&self, child: Arc<dyn ChannelOwner>)

Adopts a child object (moves from old parent to this parent).

Source

pub fn add_child(&self, guid: Arc<str>, child: Arc<dyn ChannelOwner>)

Adds a child to this parent’s registry.

Source

pub fn remove_child(&self, guid: &str)

Removes a child from this parent’s registry.

Source

pub fn on_event(&self, method: &str, params: Value)

Handles a protocol event (default implementation logs it).

Subclasses should override this to handle specific events.

Source

pub fn was_collected(&self) -> bool

Returns true if object was garbage collected.

Trait Implementations§

Source§

impl Clone for ChannelOwnerImpl

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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