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

Question: How to Expose Function associated with Trait in Rust to C++ #1313

Open
ankur19030 opened this issue Feb 8, 2024 · 1 comment
Open

Comments

@ankur19030
Copy link

How to expose the function summarize to C++ via CXX ?

pub trait Summary {
    fn summarize(&self) -> String;
}

pub struct NewsArticle {
    pub headline: String,
    pub location: String,
    pub author: String,
    pub content: String,
}

impl Summary for NewsArticle {
    fn summarize(&self) -> String {
        format!("{}, by {} ({})", self.headline, self.author, self.location)
    }
}

@volitank
Copy link

https://github.com/dtolnay/cxx/pull/672/files

This can probably help you. It's not the most graceful way, but it works.

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

No branches or pull requests

2 participants