Skip to content

Commit

Permalink
rid-macro: supporting String return types
Browse files Browse the repository at this point in the history
  • Loading branch information
thlorenz committed Jul 20, 2021
1 parent 7101524 commit ca921e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions rid-macro-impl/src/render_dart/render_pointer_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ impl Value {
use Category as C;
use Value::*;
match self {
CString => todo!("Value::render_dart_pointer_type ::CString"),
String => todo!("Value::render_dart_pointer_type ::String"),
// TODO(thlorenz): implement to_return_type for dart with the string conversion
CString => "String".to_string(),
String => "String".to_string(),
Str => todo!("Value::render_dart_pointer_type ::Str"),
Custom(type_info, _) => match type_info.cat {
// NOTE: assumes that enums are `repr(C)`.
Expand Down
6 changes: 5 additions & 1 deletion rid-macro-impl/src/render_rust/render_to_return_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ impl Value {
CString => {
quote_spanned! { res_ident.span() => let #res_pointer = #res_ident.into_raw(); }
}
String => todo!("Value::render_to_return::String"),
String => quote_spanned! { res_ident.span() =>
let cstring = ::std::ffi::CString::new(#res_ident.as_str())
.expect(&format!("Invalid string encountered"));
let #res_pointer = cstring.into_raw();
},
Str => todo!("Value::render_to_return::Str"),
Custom(type_info, type_name) => match type_info.cat {
C::Enum => {
Expand Down

0 comments on commit ca921e5

Please sign in to comment.