Skip to content

fix: return types in ffi #1

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

Merged
merged 1 commit into from
May 9, 2023
Merged

fix: return types in ffi #1

merged 1 commit into from
May 9, 2023

Conversation

Brooooooklyn
Copy link
Collaborator

No description provided.

impl AsRef<str> for ada_string {
fn as_ref(&self) -> &str {
impl ada_string {
pub fn as_str(self) -> &'static str {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is internal API, and the lifetime of &str is aligned with ada_url, so it's safe to mark it as 'static here

}
}

pub fn parse<U: AsRef<str>>(url: U) -> Result<Url, Error> {
let url_with_0_terminate = std::ffi::CString::new(url.as_ref()).unwrap();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need a parse(char* string, size_t length) API in ada to avoid memory copy here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the Rust &str is not the null-terminated

@@ -8,7 +8,7 @@ fn main() {
let mut build = cc::Build::new();
build
.file("./deps/ada.cpp")
.file("./deps/ada.h")
.include("./deps/ada.h")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is the root cause of the linking error

@Brooooooklyn Brooooooklyn merged commit a6c4650 into main May 9, 2023
@anonrig anonrig deleted the fix-bindings branch May 9, 2023 15:37
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