diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-07-01 16:07:05 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-01 22:07:05 +0000 |
commit | 6afdcf59b80b4a3ecf60f220ddff14f4309133d0 (patch) | |
tree | d6a6dad1945430e161fba9e86d93fe3d8893d89c /ops/op2/signature.rs | |
parent | 0f719aa79c2b471815c9d21014b37719c6557c1b (diff) |
refactor(ops): op2 supports strings in argument and return position (#19613)
Support strings (&str, String, and Cow) in the argument position and String in the return position. Avoids
copies where possible, though this is not always something we can do.
Diffstat (limited to 'ops/op2/signature.rs')
-rw-r--r-- | ops/op2/signature.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/ops/op2/signature.rs b/ops/op2/signature.rs index 15c40e007..5d472fcf3 100644 --- a/ops/op2/signature.rs +++ b/ops/op2/signature.rs @@ -106,6 +106,7 @@ pub enum Special { HandleScope, OpState, String, + CowStr, RefStr, FastApiCallbackOptions, } @@ -431,6 +432,17 @@ fn parse_type_path(attrs: Attributes, tp: &TypePath) -> Result<Arg, ArgError> { Err(ArgError::MissingStringAttribute) } } + ( $( std :: str :: )? str ) => { + // We should not hit this path with a #[string] argument + Err(ArgError::MissingStringAttribute) + } + ( $( std :: borrow :: )? Cow < str > ) => { + if attrs.primary == Some(AttributeModifier::String) { + Ok(Arg::Special(Special::CowStr)) + } else { + Err(ArgError::MissingStringAttribute) + } + } ( $( std :: ffi :: )? c_void ) => Ok(Arg::Numeric(NumericArg::__VOID__)), ( OpState ) => Ok(Arg::Special(Special::OpState)), ( v8 :: HandleScope ) => Ok(Arg::Special(Special::HandleScope)), |