Skip to content

Commit

Permalink
Add __swift_bridge__ to rust_string.c.h
Browse files Browse the repository at this point in the history
  • Loading branch information
NiwakaDev committed Jan 29, 2023
1 parent df6a605 commit 03245ec
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ void* __swift_bridge__$RustString$new_with_str(struct RustStr str);
uintptr_t __swift_bridge__$RustString$len(void* self);
struct RustStr __swift_bridge__$RustString$as_str(void* self);
struct RustStr __swift_bridge__$RustString$trim(void* self);
bool __swift_bridge__equality_operator_for_RustStr(struct RustStr lhs, struct RustStr rhs);
bool __swift_bridge__$RustStr$partial_eq(struct RustStr lhs, struct RustStr rhs);
2 changes: 1 addition & 1 deletion crates/swift-bridge-build/src/generate_core/string.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension RustStr: Identifiable {
}
extension RustStr: Equatable {
public static func == (lhs: RustStr, rhs: RustStr) -> Bool {
return __swift_bridge__equality_operator_for_RustStr(lhs, rhs);
return __swift_bridge__$RustStr$partial_eq(lhs, rhs);
}
}

Expand Down
20 changes: 0 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,3 @@ pub extern "C" fn __swift_bridge__null_pointer() -> *const std::ffi::c_void {

#[doc(hidden)]
pub fn assert_copy<T: Copy>() {}

#[no_mangle]
#[doc(hidden)]
pub extern "C" fn __swift_bridge__equality_operator_for_RustStr(
lhs: string::RustStr,
rhs: string::RustStr,
) -> bool {
if lhs.len != rhs.len {
return false;
}

unsafe {
for i in 0..lhs.len {
if *lhs.start.offset(i as isize) != *rhs.start.offset(i as isize) {
return false;
}
}
}
return true;
}
2 changes: 2 additions & 0 deletions src/std_bridge.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! The corresponding C and Swift code can be found in
//! crates/swift-bridge-build/src/generate_core/*
#![allow(missing_docs)]

pub mod option;
Expand Down
13 changes: 13 additions & 0 deletions src/std_bridge/string.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! The corresponding C and Swift code can be found in
//! crates/swift-bridge-build/src/generate_core/rust_string.{c.h,swift}
pub use self::ffi::*;

#[swift_bridge_macro::bridge(swift_bridge_path = crate)]
Expand Down Expand Up @@ -79,4 +81,15 @@ impl RustStr {
len: str.len(),
}
}

pub fn partial_eq(
lhs: Self,
rhs: Self,
) -> bool {

unsafe {
std::slice::from_raw_parts(lhs.start, lhs.len) ==
std::slice::from_raw_parts(rhs.start, rhs.len)
}
}
}

0 comments on commit 03245ec

Please sign in to comment.