Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let Message inherit AsAny #1204

Closed
wants to merge 1 commit into from
Closed

let Message inherit AsAny #1204

wants to merge 1 commit into from

Conversation

tinglou
Copy link

@tinglou tinglou commented Dec 12, 2024

introduce crate as as_any, and let Message inherits AsAny, then dyn Message can downcast to a concrete type easier.
Here is a example,

    fn encode(&self, msg: &dyn Message, buf: &mut Vec<u8>) -> Result<(), TcpTransportError> {
        let msg = msg
            .downcast_ref::<T>()
            .ok_or(TcpTransportError::Infallible)?;

        // println!("type name: {}", msg.type_name());
        msg.encode(buf)?;
        Ok(())
    }

@caspermeijn
Copy link
Collaborator

I don't see in what situation this would be an improvement. This is already possible with &dyn Any. Can you explain when this would be useful?

@caspermeijn
Copy link
Collaborator

Closing this for now. Please don't hesitate to re-open if you can answer the earlier question.

@caspermeijn caspermeijn closed this Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants