diff --git a/book/src/template_literals.md b/book/src/template_literals.md index d6bc850e7..31c1400af 100644 --- a/book/src/template_literals.md +++ b/book/src/template_literals.md @@ -21,9 +21,9 @@ protocol* and it can be very efficient to build complex strings out of it. [a concept borrowed from EcmaScript]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals -## The `STRING_DISPLAY` protocol +## The `DISPLAY_FMT` protocol -The `STRING_DISPLAY` protocol is a function that can be implemented by any +The `DISPLAY_FMT` protocol is a function that can be implemented by any *external* type which allows it to be used in a template string. It expects a function with the signature `fn(&self, buf: &mut String) -> fmt::Result`. @@ -40,15 +40,15 @@ pub struct StatusCode { } impl StatusCode { - #[rune::function(protocol = STRING_DISPLAY)] - fn string_display(&self, f: &mut Formatter) -> fmt::Result { + #[rune::function(protocol = DISPLAY_FMT)] + fn display_fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "{}", self.inner) } } pub fn module() -> Result { let mut module = Module::new(["http"]); - module.function_meta(StatusCode::string_display)?; + module.function_meta(StatusCode::display_fmt)?; Ok(module) } ``` @@ -62,10 +62,10 @@ types which do not implement this protocol will fail to run. ```text $> cargo run -- run scripts/book/template_literals/not_a_template.rn -== ! (`Vec` does not implement the `string_display` protocol (at 5)) (77.7µs) +== ! (`Vec` does not implement the `display_fmt` protocol (at 5)) (77.7µs) error: virtual machine error ┌─ scripts/book/template_literals/not_a_template.rn:3:9 │ 3 │ dbg!(`${vec}`); - │ ^^^^^^^^ `Vec` does not implement the `string_display` protocol + │ ^^^^^^^^ `Vec` does not implement the `display_fmt` protocol ``` diff --git a/crates/rune-core/src/protocol.rs b/crates/rune-core/src/protocol.rs index 44c551602..43be73fce 100644 --- a/crates/rune-core/src/protocol.rs +++ b/crates/rune-core/src/protocol.rs @@ -479,8 +479,8 @@ define! { }; /// Protocol function used by template strings. - pub const STRING_DISPLAY: Protocol = Protocol { - name: "STRING_DISPLAY", + pub const DISPLAY_FMT: Protocol = Protocol { + name: "DISPLAY_FMT", hash: 0x811b62957ea9d9f9u64, repr: Some("println(\"{}\", $value)"), doc: docstring! { @@ -489,8 +489,8 @@ define! { }; /// Protocol function used by custom debug impls. - pub const STRING_DEBUG: Protocol = Protocol { - name: "STRING_DEBUG", + pub const DEBUG_FMT: Protocol = Protocol { + name: "DEBUG_FMT", hash: 0x4064e3867aaa0717u64, repr: Some("println(\"{:?}\", $value)"), doc: docstring! { diff --git a/crates/rune-modules/src/base64.rs b/crates/rune-modules/src/base64.rs index d40688bc0..f6ebe77a8 100644 --- a/crates/rune-modules/src/base64.rs +++ b/crates/rune-modules/src/base64.rs @@ -94,8 +94,8 @@ impl From for DecodeError { } impl DecodeError { - #[rune::function(instance, protocol = STRING_DISPLAY)] - fn string_display(&self, f: &mut Formatter) -> VmResult<()> { + #[rune::function(instance, protocol = DISPLAY_FMT)] + fn display_fmt(&self, f: &mut Formatter) -> VmResult<()> { rune::vm_write!(f, "{}", self.inner) } } diff --git a/crates/rune-modules/src/http.rs b/crates/rune-modules/src/http.rs index 8f01c15bc..ad0e29db5 100644 --- a/crates/rune-modules/src/http.rs +++ b/crates/rune-modules/src/http.rs @@ -113,8 +113,8 @@ pub fn module(_stdio: bool) -> Result { module.function_meta(StatusCode::cmp__meta)?; module.implement_trait::(item!(::std::cmp::Ord))?; module.function_meta(StatusCode::hash__meta)?; - module.function_meta(StatusCode::string_debug__meta)?; - module.function_meta(StatusCode::string_display__meta)?; + module.function_meta(StatusCode::debug_fmt__meta)?; + module.function_meta(StatusCode::display_fmt__meta)?; module .constant( @@ -1326,7 +1326,7 @@ pub fn module(_stdio: bool) -> Result { module.function_meta(Version::cmp__meta)?; module.implement_trait::(item!(::std::cmp::Ord))?; module.function_meta(Version::hash__meta)?; - module.function_meta(Version::string_debug__meta)?; + module.function_meta(Version::debug_fmt__meta)?; module .constant( @@ -1429,7 +1429,7 @@ pub fn module(_stdio: bool) -> Result { })?; module.ty::()?; - module.function_meta(Error::string_display__meta)?; + module.function_meta(Error::display_fmt__meta)?; Ok(module) } @@ -1448,8 +1448,8 @@ impl From for Error { impl Error { /// Write a display representation the error. - #[rune::function(keep, instance, protocol = STRING_DISPLAY)] - fn string_display(&self, f: &mut Formatter) -> VmResult<()> { + #[rune::function(keep, instance, protocol = DISPLAY_FMT)] + fn display_fmt(&self, f: &mut Formatter) -> VmResult<()> { rune::vm_write!(f, "{}", self.inner) } } @@ -1800,8 +1800,8 @@ impl StatusCode { /// /// println!("{not_found:?}"); /// ``` - #[rune::function(keep, instance, protocol = STRING_DEBUG)] - fn string_debug(&self, f: &mut Formatter) -> VmResult<()> { + #[rune::function(keep, instance, protocol = DEBUG_FMT)] + fn debug_fmt(&self, f: &mut Formatter) -> VmResult<()> { rune::vm_write!(f, "{:?}", self.inner) } @@ -1816,8 +1816,8 @@ impl StatusCode { /// /// println!("{not_found}"); /// ``` - #[rune::function(keep, instance, protocol = STRING_DISPLAY)] - fn string_display(&self, f: &mut Formatter) -> VmResult<()> { + #[rune::function(keep, instance, protocol = DISPLAY_FMT)] + fn display_fmt(&self, f: &mut Formatter) -> VmResult<()> { rune::vm_write!(f, "{}", self.inner) } } @@ -1983,8 +1983,8 @@ impl Version { /// /// println!("{:?}", http2); /// ``` - #[rune::function(keep, instance, protocol = STRING_DEBUG)] - fn string_debug(&self, f: &mut Formatter) -> VmResult<()> { + #[rune::function(keep, instance, protocol = DEBUG_FMT)] + fn debug_fmt(&self, f: &mut Formatter) -> VmResult<()> { rune::vm_write!(f, "{:?}", self.inner) } } diff --git a/crates/rune-modules/src/json.rs b/crates/rune-modules/src/json.rs index 1348f45aa..816f8cbf2 100644 --- a/crates/rune-modules/src/json.rs +++ b/crates/rune-modules/src/json.rs @@ -64,12 +64,12 @@ struct Error { } impl Error { - #[rune::function(protocol = STRING_DISPLAY)] + #[rune::function(protocol = DISPLAY_FMT)] pub(crate) fn display(&self, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{}", self.error) } - #[rune::function(protocol = STRING_DEBUG)] + #[rune::function(protocol = DEBUG_FMT)] pub(crate) fn debug(&self, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{:?}", self.error) } diff --git a/crates/rune-modules/src/process.rs b/crates/rune-modules/src/process.rs index edbb048da..3a9939878 100644 --- a/crates/rune-modules/src/process.rs +++ b/crates/rune-modules/src/process.rs @@ -60,7 +60,7 @@ pub fn module(_stdio: bool) -> Result { module.function_meta(Command::new__meta)?; module.function_meta(Command::arg__meta)?; module.function_meta(Command::args__meta)?; - module.function_meta(Command::string_debug__meta)?; + module.function_meta(Command::debug_fmt__meta)?; #[cfg(unix)] module.function_meta(Command::arg0__meta)?; module.function_meta(Command::stdin__meta)?; @@ -70,7 +70,7 @@ pub fn module(_stdio: bool) -> Result { module.function_meta(Command::spawn__meta)?; module.ty::()?; - module.function_meta(Child::string_debug__meta)?; + module.function_meta(Child::debug_fmt__meta)?; module.function_meta(Child::stdin__meta)?; module.function_meta(Child::stdout__meta)?; module.function_meta(Child::stderr__meta)?; @@ -83,28 +83,28 @@ pub fn module(_stdio: bool) -> Result { module.ty::()?; module.function_meta(ExitStatus::code__meta)?; module.function_meta(ExitStatus::success__meta)?; - module.function_meta(ExitStatus::string_display__meta)?; - module.function_meta(ExitStatus::string_debug__meta)?; + module.function_meta(ExitStatus::display_fmt__meta)?; + module.function_meta(ExitStatus::debug_fmt__meta)?; module.ty::()?; - module.function_meta(Output::string_debug__meta)?; + module.function_meta(Output::debug_fmt__meta)?; module.ty::()?; module.function_meta(Stdio::null__meta)?; module.function_meta(Stdio::inherit__meta)?; module.function_meta(Stdio::piped__meta)?; - module.function_meta(Stdio::string_debug__meta)?; + module.function_meta(Stdio::debug_fmt__meta)?; module.ty::()?; - module.function_meta(ChildStdin::string_debug__meta)?; + module.function_meta(ChildStdin::debug_fmt__meta)?; module.function_meta(ChildStdin::try_into_stdio__meta)?; module.ty::()?; - module.function_meta(ChildStdout::string_debug__meta)?; + module.function_meta(ChildStdout::debug_fmt__meta)?; module.function_meta(ChildStdout::try_into_stdio__meta)?; module.ty::()?; - module.function_meta(ChildStderr::string_debug__meta)?; + module.function_meta(ChildStderr::debug_fmt__meta)?; module.function_meta(ChildStderr::try_into_stdio__meta)?; Ok(module) @@ -424,8 +424,8 @@ impl Command { }) } - #[rune::function(keep, protocol = STRING_DEBUG)] - fn string_debug(&self, f: &mut Formatter) -> VmResult<()> { + #[rune::function(keep, protocol = DEBUG_FMT)] + fn debug_fmt(&self, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{self:?}") } } @@ -616,8 +616,8 @@ impl Child { }) } - #[rune::function(keep, protocol = STRING_DEBUG)] - fn string_debug(&self, f: &mut Formatter) -> VmResult<()> { + #[rune::function(keep, protocol = DEBUG_FMT)] + fn debug_fmt(&self, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{:?}", self.inner) } } @@ -644,8 +644,8 @@ struct Output { } impl Output { - #[rune::function(keep, protocol = STRING_DEBUG)] - fn string_debug(&self, f: &mut Formatter) -> VmResult<()> { + #[rune::function(keep, protocol = DEBUG_FMT)] + fn debug_fmt(&self, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{self:?}") } } @@ -713,13 +713,13 @@ impl ExitStatus { self.inner.code() } - #[rune::function(keep, protocol = STRING_DISPLAY)] - fn string_display(&self, f: &mut Formatter) -> VmResult<()> { + #[rune::function(keep, protocol = DISPLAY_FMT)] + fn display_fmt(&self, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{}", self.inner) } - #[rune::function(keep, protocol = STRING_DEBUG)] - fn string_debug(&self, f: &mut Formatter) -> VmResult<()> { + #[rune::function(keep, protocol = DEBUG_FMT)] + fn debug_fmt(&self, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{:?}", self.inner) } } @@ -756,8 +756,8 @@ impl Stdio { } } - #[rune::function(keep, protocol = STRING_DEBUG)] - fn string_debug(&self, f: &mut Formatter) -> VmResult<()> { + #[rune::function(keep, protocol = DEBUG_FMT)] + fn debug_fmt(&self, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{:?}", self.inner) } } @@ -784,8 +784,8 @@ macro_rules! stdio_stream { }) } - #[rune::function(keep, protocol = STRING_DEBUG)] - fn string_debug(&self, f: &mut Formatter) -> VmResult<()> { + #[rune::function(keep, protocol = DEBUG_FMT)] + fn debug_fmt(&self, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{:?}", self.inner) } } diff --git a/crates/rune-modules/src/time.rs b/crates/rune-modules/src/time.rs index 99ff2f632..81de3e943 100644 --- a/crates/rune-modules/src/time.rs +++ b/crates/rune-modules/src/time.rs @@ -74,7 +74,7 @@ pub fn module(_stdio: bool) -> Result { m.function_meta(Duration::cmp__meta)?; m.implement_trait::(item!(::std::cmp::Ord))?; m.function_meta(Duration::hash__meta)?; - m.function_meta(Duration::string_debug__meta)?; + m.function_meta(Duration::debug_fmt__meta)?; m.function_meta(Duration::clone__meta)?; m.implement_trait::(item!(::std::clone::Clone))?; @@ -208,7 +208,7 @@ pub fn module(_stdio: bool) -> Result { m.function_meta(Instant::cmp__meta)?; m.implement_trait::(item!(::std::cmp::Ord))?; m.function_meta(Instant::hash__meta)?; - m.function_meta(Instant::string_debug__meta)?; + m.function_meta(Instant::debug_fmt__meta)?; m.function_meta(Instant::clone__meta)?; m.implement_trait::(item!(::std::clone::Clone))?; @@ -841,8 +841,8 @@ impl Duration { /// /// println!("{second:?}"); /// ``` - #[rune::function(keep, instance, protocol = STRING_DEBUG)] - fn string_debug(&self, f: &mut Formatter) -> VmResult<()> { + #[rune::function(keep, instance, protocol = DEBUG_FMT)] + fn debug_fmt(&self, f: &mut Formatter) -> VmResult<()> { rune::vm_write!(f, "{:?}", self.inner) } @@ -1290,8 +1290,8 @@ impl Instant { /// /// println!("{now:?}"); /// ``` - #[rune::function(keep, instance, protocol = STRING_DEBUG)] - fn string_debug(&self, f: &mut Formatter) -> VmResult<()> { + #[rune::function(keep, instance, protocol = DEBUG_FMT)] + fn debug_fmt(&self, f: &mut Formatter) -> VmResult<()> { rune::vm_write!(f, "{:?}", self.inner) } diff --git a/crates/rune-modules/src/toml.rs b/crates/rune-modules/src/toml.rs index d39975362..c297bffb6 100644 --- a/crates/rune-modules/src/toml.rs +++ b/crates/rune-modules/src/toml.rs @@ -65,12 +65,12 @@ pub mod de { } impl Error { - #[rune::function(protocol = STRING_DISPLAY)] + #[rune::function(protocol = DISPLAY_FMT)] pub(crate) fn display(&self, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{}", self.error) } - #[rune::function(protocol = STRING_DEBUG)] + #[rune::function(protocol = DEBUG_FMT)] pub(crate) fn debug(&self, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{:?}", self.error) } @@ -105,12 +105,12 @@ pub mod ser { } impl Error { - #[rune::function(protocol = STRING_DISPLAY)] + #[rune::function(protocol = DISPLAY_FMT)] pub(crate) fn display(&self, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{}", self.error) } - #[rune::function(protocol = STRING_DEBUG)] + #[rune::function(protocol = DEBUG_FMT)] pub(crate) fn debug(&self, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{:?}", self.error) } diff --git a/crates/rune/src/lib.rs b/crates/rune/src/lib.rs index c03746ab7..0861c9fb2 100644 --- a/crates/rune/src/lib.rs +++ b/crates/rune/src/lib.rs @@ -297,7 +297,7 @@ pub(crate) use rune_macros::__internal_impl_any; /// Type::name)]` argument. If `instance` is specified it is an associated /// instance function that can be defined externally. /// * Instance functions can be made a protocol function -/// `#[rune::function(protocol = STRING_DISPLAY)]`. +/// `#[rune::function(protocol = DISPLAY_FMT)]`. /// /// # Instance and associated functions /// @@ -408,8 +408,8 @@ pub(crate) use rune_macros::__internal_impl_any; /// /* .. */ /// } /// -/// #[rune::function(instance, protocol = STRING_DISPLAY)] -/// fn string_display(this: &Struct, f: &mut Formatter) -> VmResult<()> { +/// #[rune::function(instance, protocol = DISPLAY_FMT)] +/// fn display_fmt(this: &Struct, f: &mut Formatter) -> VmResult<()> { /// /* .. */ /// # todo!() /// } @@ -497,7 +497,7 @@ pub(crate) use rune_macros::__internal_impl_any; /// } /// } /// -/// /// Display the string using the [`STRING_DISPLAY`] protocol. +/// /// Display the string using the [`DISPLAY_FMT`] protocol. /// /// /// /// # Examples /// /// @@ -505,7 +505,7 @@ pub(crate) use rune_macros::__internal_impl_any; /// /// let string = String::new("hello"); /// /// assert_eq!(format!("{}", string), "hello"); /// /// ``` -/// #[rune::function(protocol = STRING_DISPLAY)] +/// #[rune::function(protocol = DISPLAY_FMT)] /// fn display(&self, f: &mut Formatter) -> VmResult<()> { /// vm_write!(f, "{}", self.inner); /// VmResult::Ok(()) diff --git a/crates/rune/src/module/module.rs b/crates/rune/src/module/module.rs index 69bdedd20..fc8f30605 100644 --- a/crates/rune/src/module/module.rs +++ b/crates/rune/src/module/module.rs @@ -1114,8 +1114,8 @@ impl Module { /// /* .. */ /// } /// - /// #[rune::function(instance, protocol = STRING_DISPLAY)] - /// fn string_display(this: &Struct, f: &mut Formatter) -> std::fmt::Result { + /// #[rune::function(instance, protocol = DISPLAY_FMT)] + /// fn display_fmt(this: &Struct, f: &mut Formatter) -> std::fmt::Result { /// /* .. */ /// # todo!() /// } diff --git a/crates/rune/src/modules/any.rs b/crates/rune/src/modules/any.rs index a3d1e38f2..c86f2085b 100644 --- a/crates/rune/src/modules/any.rs +++ b/crates/rune/src/modules/any.rs @@ -52,7 +52,7 @@ fn type_of_val(value: Value) -> VmResult { /// /// assert_eq!(format!("{}", any::Type::of_val(42)), "Type(0x1cad9186c9641c4f)"); /// ``` -#[rune::function(instance, protocol = STRING_DISPLAY)] +#[rune::function(instance, protocol = DISPLAY_FMT)] fn format_type(ty: Type, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{:?}", ty) } diff --git a/crates/rune/src/modules/bytes.rs b/crates/rune/src/modules/bytes.rs index 799d612fe..0308afeba 100644 --- a/crates/rune/src/modules/bytes.rs +++ b/crates/rune/src/modules/bytes.rs @@ -50,7 +50,7 @@ pub fn module() -> Result { m.function_meta(hash__meta)?; - m.function_meta(string_debug__meta)?; + m.function_meta(debug_fmt__meta)?; Ok(m) } @@ -439,9 +439,9 @@ fn hash(this: &[u8], hasher: &mut Hasher) { /// ```rune /// println!("{:?}", b"Hello"); /// ``` -#[rune::function(keep, instance, protocol = STRING_DEBUG)] +#[rune::function(keep, instance, protocol = DEBUG_FMT)] #[inline] -fn string_debug(this: &[u8], f: &mut Formatter) -> VmResult<()> { +fn debug_fmt(this: &[u8], f: &mut Formatter) -> VmResult<()> { rune::vm_write!(f, "{this:?}") } diff --git a/crates/rune/src/modules/cmp.rs b/crates/rune/src/modules/cmp.rs index 913101069..f31b2cefc 100644 --- a/crates/rune/src/modules/cmp.rs +++ b/crates/rune/src/modules/cmp.rs @@ -64,7 +64,7 @@ pub fn module() -> Result { m.function_meta(ordering_eq__meta)?; m.implement_trait::(rune::item!(::std::cmp::Eq))?; - m.function_meta(ordering_string_debug)?; + m.function_meta(ordering_debug_fmt)?; m.function_meta(min__meta)?; m.function_meta(max__meta)?; @@ -779,7 +779,7 @@ fn ordering_eq(this: Ordering, other: Ordering) -> bool { /// /// assert_eq!(format!("{:?}", Ordering::Less), "Less"); /// ``` -#[rune::function(instance, protocol = STRING_DEBUG)] -fn ordering_string_debug(this: Ordering, s: &mut Formatter) -> VmResult<()> { +#[rune::function(instance, protocol = DEBUG_FMT)] +fn ordering_debug_fmt(this: Ordering, s: &mut Formatter) -> VmResult<()> { vm_write!(s, "{:?}", this) } diff --git a/crates/rune/src/modules/collections/hash_map.rs b/crates/rune/src/modules/collections/hash_map.rs index 738982e83..969923d41 100644 --- a/crates/rune/src/modules/collections/hash_map.rs +++ b/crates/rune/src/modules/collections/hash_map.rs @@ -32,7 +32,7 @@ pub fn module() -> Result { m.function_meta(HashMap::extend__meta)?; m.function_meta(HashMap::index_set__meta)?; m.function_meta(HashMap::index_get__meta)?; - m.function_meta(HashMap::string_debug__meta)?; + m.function_meta(HashMap::debug_fmt__meta)?; m.function_meta(HashMap::clone__meta)?; m.implement_trait::(rune::item!(::std::clone::Clone))?; @@ -506,12 +506,12 @@ impl HashMap { /// /// assert_eq!(format!("{:?}", map), "{1: \"a\"}"); /// ``` - #[rune::function(keep, protocol = STRING_DEBUG)] - fn string_debug(&self, f: &mut Formatter) -> VmResult<()> { - self.string_debug_with(f, &mut EnvProtocolCaller) + #[rune::function(keep, protocol = DEBUG_FMT)] + fn debug_fmt(&self, f: &mut Formatter) -> VmResult<()> { + self.debug_fmt_with(f, &mut EnvProtocolCaller) } - pub(crate) fn string_debug_with( + pub(crate) fn debug_fmt_with( &self, f: &mut Formatter, caller: &mut dyn ProtocolCaller, @@ -521,9 +521,9 @@ impl HashMap { let mut it = self.table.iter().peekable(); while let Some((key, value)) = it.next() { - vm_try!(key.string_debug_with(f, caller)); + vm_try!(key.debug_fmt_with(f, caller)); vm_try!(vm_write!(f, ": ")); - vm_try!(value.string_debug_with(f, caller)); + vm_try!(value.debug_fmt_with(f, caller)); if it.peek().is_some() { vm_try!(vm_write!(f, ", ")); diff --git a/crates/rune/src/modules/collections/hash_set.rs b/crates/rune/src/modules/collections/hash_set.rs index 98ed82442..1d8ee04b3 100644 --- a/crates/rune/src/modules/collections/hash_set.rs +++ b/crates/rune/src/modules/collections/hash_set.rs @@ -32,7 +32,7 @@ pub fn module() -> Result { m.function_meta(HashSet::iter__meta)?; m.function_meta(HashSet::into_iter__meta)?; m.function_meta(HashSet::from_iter__meta)?; - m.function_meta(HashSet::string_debug__meta)?; + m.function_meta(HashSet::debug_fmt__meta)?; m.function_meta(HashSet::clone__meta)?; m.implement_trait::(rune::item!(::std::clone::Clone))?; @@ -411,7 +411,7 @@ impl HashSet { /// Write a debug representation to a string. /// - /// This calls the [`STRING_DEBUG`] protocol over all elements of the + /// This calls the [`DEBUG_FMT`] protocol over all elements of the /// collection. /// /// # Examples @@ -422,12 +422,12 @@ impl HashSet { /// let set = HashSet::from_iter([1, 2, 3]); /// println!("{:?}", set); /// ``` - #[rune::function(keep, protocol = STRING_DEBUG)] - fn string_debug(&self, f: &mut Formatter) -> VmResult<()> { - self.string_debug_with(f, &mut EnvProtocolCaller) + #[rune::function(keep, protocol = DEBUG_FMT)] + fn debug_fmt(&self, f: &mut Formatter) -> VmResult<()> { + self.debug_fmt_with(f, &mut EnvProtocolCaller) } - fn string_debug_with(&self, f: &mut Formatter, _: &mut dyn ProtocolCaller) -> VmResult<()> { + fn debug_fmt_with(&self, f: &mut Formatter, _: &mut dyn ProtocolCaller) -> VmResult<()> { vm_try!(vm_write!(f, "{{")); let mut it = self.table.iter().peekable(); diff --git a/crates/rune/src/modules/collections/vec_deque.rs b/crates/rune/src/modules/collections/vec_deque.rs index 15f385475..71f317d2d 100644 --- a/crates/rune/src/modules/collections/vec_deque.rs +++ b/crates/rune/src/modules/collections/vec_deque.rs @@ -43,7 +43,7 @@ pub fn module() -> Result { m.associated_function(Protocol::INDEX_GET, VecDeque::get)?; m.associated_function(Protocol::INDEX_SET, VecDeque::set)?; - m.function_meta(VecDeque::string_debug)?; + m.function_meta(VecDeque::debug_fmt)?; m.function_meta(VecDeque::partial_eq__meta)?; m.implement_trait::(rune::item!(::std::cmp::PartialEq))?; @@ -562,7 +562,7 @@ impl VecDeque { /// Write a debug representation to a string. /// - /// This calls the [`STRING_DEBUG`] protocol over all elements of the + /// This calls the [`DEBUG_FMT`] protocol over all elements of the /// collection. /// /// # Examples @@ -573,23 +573,19 @@ impl VecDeque { /// let deque = VecDeque::from::([1, 2, 3]); /// assert_eq!(format!("{:?}", deque), "[1, 2, 3]"); /// ``` - #[rune::function(protocol = STRING_DEBUG)] - fn string_debug(&self, f: &mut Formatter) -> VmResult<()> { - self.string_debug_with(f, &mut EnvProtocolCaller) + #[rune::function(protocol = DEBUG_FMT)] + fn debug_fmt(&self, f: &mut Formatter) -> VmResult<()> { + self.debug_fmt_with(f, &mut EnvProtocolCaller) } #[inline] - fn string_debug_with( - &self, - f: &mut Formatter, - caller: &mut dyn ProtocolCaller, - ) -> VmResult<()> { + fn debug_fmt_with(&self, f: &mut Formatter, caller: &mut dyn ProtocolCaller) -> VmResult<()> { let mut it = self.inner.iter().peekable(); vm_try!(vm_write!(f, "[")); while let Some(value) = it.next() { - vm_try!(value.string_debug_with(f, caller)); + vm_try!(value.debug_fmt_with(f, caller)); if it.peek().is_some() { vm_try!(vm_write!(f, ", ")); diff --git a/crates/rune/src/modules/fmt.rs b/crates/rune/src/modules/fmt.rs index 83b84f4bc..19d67a9ee 100644 --- a/crates/rune/src/modules/fmt.rs +++ b/crates/rune/src/modules/fmt.rs @@ -28,20 +28,20 @@ pub fn module() -> Result { m.ty::()?; m.ty::()?; - m.function_meta(fmt_error_string_display)?; + m.function_meta(fmt_error_display_fmt)?; m.macro_meta(format)?; m.ty::()?; - m.function_meta(format_string_display__meta)?; - m.function_meta(format_string_debug__meta)?; + m.function_meta(format_display_fmt__meta)?; + m.function_meta(format_debug_fmt__meta)?; m.function_meta(format_clone__meta)?; m.implement_trait::(rune::item!(::std::clone::Clone))?; Ok(m) } -#[rune::function(instance, protocol = STRING_DISPLAY)] -fn fmt_error_string_display(error: &fmt::Error, f: &mut Formatter) -> VmResult<()> { +#[rune::function(instance, protocol = DISPLAY_FMT)] +fn fmt_error_display_fmt(error: &fmt::Error, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{error}") } @@ -74,8 +74,8 @@ pub(crate) fn format( /// let value = #[builtin] format!("Hello", fill = '0', width = 10); /// assert_eq!(format!("{value}"), "Hello00000"); /// ``` -#[rune::function(keep, instance, protocol = STRING_DISPLAY)] -fn format_string_display(format: &Format, f: &mut Formatter) -> VmResult<()> { +#[rune::function(keep, instance, protocol = DISPLAY_FMT)] +fn format_display_fmt(format: &Format, f: &mut Formatter) -> VmResult<()> { VmResult::Ok(vm_try!(format.spec.format( &format.value, f, @@ -92,8 +92,8 @@ fn format_string_display(format: &Format, f: &mut Formatter) -> VmResult<()> { /// let string = format!("{value:?}"); /// assert!(string is String); /// ``` -#[rune::function(keep, instance, protocol = STRING_DEBUG)] -fn format_string_debug(format: &Format, f: &mut Formatter) -> VmResult<()> { +#[rune::function(keep, instance, protocol = DEBUG_FMT)] +fn format_debug_fmt(format: &Format, f: &mut Formatter) -> VmResult<()> { VmResult::Ok(vm_try!(vm_write!(f, "{format:?}"))) } diff --git a/crates/rune/src/modules/io.rs b/crates/rune/src/modules/io.rs index 36546ceea..f6e32afd8 100644 --- a/crates/rune/src/modules/io.rs +++ b/crates/rune/src/modules/io.rs @@ -39,9 +39,9 @@ pub fn module( #[cfg(feature = "std")] module.ty::()?; #[cfg(feature = "std")] - module.function_meta(io_error_string_display)?; + module.function_meta(io_error_display_fmt)?; #[cfg(feature = "std")] - module.function_meta(io_error_string_debug)?; + module.function_meta(io_error_debug_fmt)?; #[cfg(feature = "std")] if stdio { @@ -80,15 +80,15 @@ pub fn module( Ok(module) } -#[rune::function(instance, protocol = STRING_DISPLAY)] +#[rune::function(instance, protocol = DISPLAY_FMT)] #[cfg(feature = "std")] -fn io_error_string_display(error: &io::Error, f: &mut Formatter) -> VmResult<()> { +fn io_error_display_fmt(error: &io::Error, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{error}") } -#[rune::function(instance, protocol = STRING_DEBUG)] +#[rune::function(instance, protocol = DEBUG_FMT)] #[cfg(feature = "std")] -fn io_error_string_debug(error: &io::Error, f: &mut Formatter) -> VmResult<()> { +fn io_error_debug_fmt(error: &io::Error, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{error:?}") } diff --git a/crates/rune/src/modules/mem.rs b/crates/rune/src/modules/mem.rs index 614de8366..43ba4e909 100644 --- a/crates/rune/src/modules/mem.rs +++ b/crates/rune/src/modules/mem.rs @@ -84,12 +84,12 @@ impl Snapshot { self.inner.is_exclusive() } - #[rune::function(protocol = STRING_DISPLAY)] + #[rune::function(protocol = DISPLAY_FMT)] fn display(&self, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{}", self.inner) } - #[rune::function(protocol = STRING_DEBUG)] + #[rune::function(protocol = DEBUG_FMT)] fn debug(&self, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{:?}", self.inner) } diff --git a/crates/rune/src/modules/ops.rs b/crates/rune/src/modules/ops.rs index faf8bd851..c7111b3c6 100644 --- a/crates/rune/src/modules/ops.rs +++ b/crates/rune/src/modules/ops.rs @@ -187,7 +187,7 @@ pub fn module() -> Result { m.function_meta(ControlFlow::eq__meta)?; m.implement_trait::(rune::item!(::std::cmp::Eq))?; - m.function_meta(ControlFlow::string_debug__meta)?; + m.function_meta(ControlFlow::debug_fmt__meta)?; m.function_meta(ControlFlow::clone__meta)?; m.implement_trait::(rune::item!(::std::clone::Clone))?; diff --git a/crates/rune/src/modules/ops/generator.rs b/crates/rune/src/modules/ops/generator.rs index 3c8d0917c..44bb4499c 100644 --- a/crates/rune/src/modules/ops/generator.rs +++ b/crates/rune/src/modules/ops/generator.rs @@ -179,7 +179,7 @@ fn generator_into_iter(this: Generator) -> Iter { /// /// println!("{a:?}"); /// `` -#[rune::function(keep, instance, protocol = STRING_DEBUG)] +#[rune::function(keep, instance, protocol = DEBUG_FMT)] fn generator_debug(this: &Generator, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{this:?}") } @@ -274,17 +274,17 @@ fn generator_state_eq(this: &GeneratorState, other: &GeneratorState) -> VmResult /// println!("{a:?}"); /// println!("{b:?}"); /// `` -#[rune::function(keep, instance, protocol = STRING_DEBUG)] +#[rune::function(keep, instance, protocol = DEBUG_FMT)] fn generator_state_debug(this: &GeneratorState, f: &mut Formatter) -> VmResult<()> { match this { GeneratorState::Yielded(value) => { vm_try!(vm_write!(f, "Yielded(")); - vm_try!(value.string_debug_with(f, &mut EnvProtocolCaller)); + vm_try!(value.debug_fmt_with(f, &mut EnvProtocolCaller)); vm_try!(vm_write!(f, ")")); } GeneratorState::Complete(value) => { vm_try!(vm_write!(f, "Complete(")); - vm_try!(value.string_debug_with(f, &mut EnvProtocolCaller)); + vm_try!(value.debug_fmt_with(f, &mut EnvProtocolCaller)); vm_try!(vm_write!(f, ")")); } } diff --git a/crates/rune/src/modules/option.rs b/crates/rune/src/modules/option.rs index a8c723015..8f172183d 100644 --- a/crates/rune/src/modules/option.rs +++ b/crates/rune/src/modules/option.rs @@ -89,7 +89,7 @@ fn expect(option: Option, message: Value) -> VmResult { let mut s = String::new(); // SAFETY: Formatter does not outlive the string it references. let mut f = unsafe { Formatter::new(NonNull::from(&mut s)) }; - vm_try!(message.string_display(&mut f)); + vm_try!(message.display_fmt(&mut f)); VmResult::err(Panic::custom(s)) } } diff --git a/crates/rune/src/modules/result.rs b/crates/rune/src/modules/result.rs index 377a44261..ebc0e3d0c 100644 --- a/crates/rune/src/modules/result.rs +++ b/crates/rune/src/modules/result.rs @@ -206,9 +206,9 @@ fn expect(result: Result, message: Value) -> VmResult { let mut s = String::new(); // SAFETY: Formatter does not outlive the string it references. let mut f = unsafe { Formatter::new(NonNull::from(&mut s)) }; - vm_try!(message.string_display(&mut f)); + vm_try!(message.display_fmt(&mut f)); vm_try!(f.try_write_str(": ")); - vm_try!(err.string_debug(&mut f)); + vm_try!(err.debug_fmt(&mut f)); VmResult::err(Panic::custom(s)) } } diff --git a/crates/rune/src/modules/string.rs b/crates/rune/src/modules/string.rs index 0d0209293..40b0aa4fc 100644 --- a/crates/rune/src/modules/string.rs +++ b/crates/rune/src/modules/string.rs @@ -90,8 +90,8 @@ pub fn module() -> Result { m.function_meta(hash__meta)?; - m.function_meta(string_display__meta)?; - m.function_meta(string_debug__meta)?; + m.function_meta(display_fmt__meta)?; + m.function_meta(debug_fmt__meta)?; m.ty::()?; m.function_meta(Chars::next__meta)?; @@ -741,9 +741,9 @@ fn hash(this: &str, hasher: &mut Hasher) { /// ```rune /// println!("{}", "Hello"); /// ``` -#[rune::function(keep, instance, protocol = STRING_DISPLAY)] +#[rune::function(keep, instance, protocol = DISPLAY_FMT)] #[inline] -fn string_display(this: &str, f: &mut Formatter) -> VmResult<()> { +fn display_fmt(this: &str, f: &mut Formatter) -> VmResult<()> { rune::vm_write!(f, "{this}") } @@ -754,9 +754,9 @@ fn string_display(this: &str, f: &mut Formatter) -> VmResult<()> { /// ```rune /// println!("{:?}", "Hello"); /// ``` -#[rune::function(keep, instance, protocol = STRING_DEBUG)] +#[rune::function(keep, instance, protocol = DEBUG_FMT)] #[inline] -fn string_debug(this: &str, f: &mut Formatter) -> VmResult<()> { +fn debug_fmt(this: &str, f: &mut Formatter) -> VmResult<()> { rune::vm_write!(f, "{this:?}") } diff --git a/crates/rune/src/modules/tuple.rs b/crates/rune/src/modules/tuple.rs index 52d0d7540..215a7d63f 100644 --- a/crates/rune/src/modules/tuple.rs +++ b/crates/rune/src/modules/tuple.rs @@ -69,7 +69,7 @@ pub fn module() -> Result { m.implement_trait::(rune::item!(::std::clone::Clone))?; m.function_meta(hash__meta)?; - m.function_meta(string_debug__meta)?; + m.function_meta(debug_fmt__meta)?; Ok(m) } @@ -270,8 +270,8 @@ fn clone(this: &Tuple) -> VmResult { /// let a = (1, 2, 3); /// println!("{a:?}"); /// ``` -#[rune::function(keep, instance, protocol = STRING_DEBUG)] +#[rune::function(keep, instance, protocol = DEBUG_FMT)] #[inline] -fn string_debug(this: &Tuple, f: &mut Formatter) -> VmResult<()> { - this.string_debug_with(f, &mut EnvProtocolCaller) +fn debug_fmt(this: &Tuple, f: &mut Formatter) -> VmResult<()> { + this.debug_fmt_with(f, &mut EnvProtocolCaller) } diff --git a/crates/rune/src/modules/vec.rs b/crates/rune/src/modules/vec.rs index 2f933e94a..cf43f513a 100644 --- a/crates/rune/src/modules/vec.rs +++ b/crates/rune/src/modules/vec.rs @@ -80,7 +80,7 @@ pub fn module() -> Result { m.function_meta(index_get)?; m.function_meta(index_set)?; m.function_meta(resize)?; - m.function_meta(string_debug__meta)?; + m.function_meta(debug_fmt__meta)?; m.function_meta(clone__meta)?; m.implement_trait::(rune::item!(::std::clone::Clone))?; @@ -603,7 +603,7 @@ fn resize(this: &mut Vec, new_len: usize, value: Value) -> VmResult<()> { /// Write a debug representation to a string. /// -/// This calls the [`STRING_DEBUG`] protocol over all elements of the +/// This calls the [`DEBUG_FMT`] protocol over all elements of the /// collection. /// /// # Examples @@ -612,9 +612,9 @@ fn resize(this: &mut Vec, new_len: usize, value: Value) -> VmResult<()> { /// let vec = [1, 2, 3]; /// assert_eq!(format!("{:?}", vec), "[1, 2, 3]"); /// ``` -#[rune::function(keep, instance, protocol = STRING_DEBUG)] -fn string_debug(this: &Vec, f: &mut Formatter) -> VmResult<()> { - Vec::string_debug_with(this, f, &mut EnvProtocolCaller) +#[rune::function(keep, instance, protocol = DEBUG_FMT)] +fn debug_fmt(this: &Vec, f: &mut Formatter) -> VmResult<()> { + Vec::debug_fmt_with(this, f, &mut EnvProtocolCaller) } /// Perform a partial equality check with this vector. diff --git a/crates/rune/src/runtime/control_flow.rs b/crates/rune/src/runtime/control_flow.rs index 23b2fbfb5..636b9feed 100644 --- a/crates/rune/src/runtime/control_flow.rs +++ b/crates/rune/src/runtime/control_flow.rs @@ -122,12 +122,12 @@ impl ControlFlow { /// /// let string = format!("{:?}", ControlFlow::Continue(true)); /// ``` - #[rune::function(keep, protocol = STRING_DEBUG)] - pub(crate) fn string_debug(&self, f: &mut Formatter) -> VmResult<()> { - Self::string_debug_with(self, f, &mut EnvProtocolCaller) + #[rune::function(keep, protocol = DEBUG_FMT)] + pub(crate) fn debug_fmt(&self, f: &mut Formatter) -> VmResult<()> { + Self::debug_fmt_with(self, f, &mut EnvProtocolCaller) } - pub(crate) fn string_debug_with( + pub(crate) fn debug_fmt_with( &self, f: &mut Formatter, caller: &mut dyn ProtocolCaller, @@ -135,12 +135,12 @@ impl ControlFlow { match self { ControlFlow::Continue(value) => { vm_try!(vm_write!(f, "Continue(")); - vm_try!(Value::string_debug_with(value, f, caller)); + vm_try!(Value::debug_fmt_with(value, f, caller)); vm_try!(vm_write!(f, ")")); } ControlFlow::Break(value) => { vm_try!(vm_write!(f, "Break(")); - vm_try!(Value::string_debug_with(value, f, caller)); + vm_try!(Value::debug_fmt_with(value, f, caller)); vm_try!(vm_write!(f, ")")); } } diff --git a/crates/rune/src/runtime/env.rs b/crates/rune/src/runtime/env.rs index c2ab3d915..fd6cfbdb5 100644 --- a/crates/rune/src/runtime/env.rs +++ b/crates/rune/src/runtime/env.rs @@ -2,7 +2,7 @@ //! //! This provides access to functions to call specific protocol functions, like: //! * [super::Value::into_iter] -//! * [super::Value::string_debug] +//! * [super::Value::debug_fmt] //! * [super::Value::into_type_name] //! //! See the corresponding function for documentation. diff --git a/crates/rune/src/runtime/fmt.rs b/crates/rune/src/runtime/fmt.rs index d5553cddf..8b86f4c04 100644 --- a/crates/rune/src/runtime/fmt.rs +++ b/crates/rune/src/runtime/fmt.rs @@ -6,11 +6,11 @@ use crate::Any; /// A formatter for the rune virtual machine. /// -/// This is used as a receiver to functions implementing the [`STRING_DEBUG`] -/// and [`STRING_DISPLAY`] protocols. +/// This is used as a receiver to functions implementing the [`DEBUG_FMT`] +/// and [`DISPLAY_FMT`] protocols. /// -/// [`STRING_DEBUG`]: crate::runtime::Protocol::STRING_DEBUG -/// [`STRING_DISPLAY`]: crate::runtime::Protocol::STRING_DISPLAY +/// [`DEBUG_FMT`]: crate::runtime::Protocol::DEBUG_FMT +/// [`DISPLAY_FMT`]: crate::runtime::Protocol::DISPLAY_FMT #[derive(Any)] #[rune(crate, item = ::std::fmt)] pub struct Formatter { diff --git a/crates/rune/src/runtime/format.rs b/crates/rune/src/runtime/format.rs index 0cb24ad06..c35943afa 100644 --- a/crates/rune/src/runtime/format.rs +++ b/crates/rune/src/runtime/format.rs @@ -246,7 +246,7 @@ impl FormatSpec { return VmResult::Ok(()); } - value.string_display_with(f, caller) + value.display_fmt_with(f, caller) } fn format_debug( @@ -289,7 +289,7 @@ impl FormatSpec { return VmResult::Ok(()); }; - value.string_debug_with(f, caller) + value.debug_fmt_with(f, caller) } fn format_upper_hex(&self, value: &Value, f: &mut Formatter) -> VmResult<()> { diff --git a/crates/rune/src/runtime/stream.rs b/crates/rune/src/runtime/stream.rs index 855cfc561..53edc7fc1 100644 --- a/crates/rune/src/runtime/stream.rs +++ b/crates/rune/src/runtime/stream.rs @@ -192,7 +192,7 @@ impl Stream { /// /// println!("{a:?}"); /// `` - #[rune::function(keep, instance, protocol = STRING_DEBUG)] + #[rune::function(keep, instance, protocol = DEBUG_FMT)] fn debug(&self, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{self:?}") } diff --git a/crates/rune/src/runtime/tuple.rs b/crates/rune/src/runtime/tuple.rs index e37fa160b..b5657e32b 100644 --- a/crates/rune/src/runtime/tuple.rs +++ b/crates/rune/src/runtime/tuple.rs @@ -69,7 +69,7 @@ impl Tuple { VmResult::Ok(()) } - pub(crate) fn string_debug_with( + pub(crate) fn debug_fmt_with( &self, f: &mut Formatter, caller: &mut dyn ProtocolCaller, @@ -78,7 +78,7 @@ impl Tuple { vm_try!(vm_write!(f, "(")); while let Some(value) = it.next() { - vm_try!(value.string_debug_with(f, caller)); + vm_try!(value.debug_fmt_with(f, caller)); if it.peek().is_some() { vm_try!(vm_write!(f, ", ")); diff --git a/crates/rune/src/runtime/value.rs b/crates/rune/src/runtime/value.rs index 99e6a8cd7..91e627f84 100644 --- a/crates/rune/src/runtime/value.rs +++ b/crates/rune/src/runtime/value.rs @@ -329,7 +329,7 @@ impl Value { Self { repr: Repr::Empty } } - /// Format the value using the [Protocol::STRING_DISPLAY] protocol. + /// Format the value using the [Protocol::DISPLAY_FMT] protocol. /// /// Requires a work buffer `buf` which will be used in case the value /// provided requires out-of-line formatting. This must be cleared between @@ -343,13 +343,13 @@ impl Value { /// # Panics /// /// This function will panic if called outside of a virtual machine. - pub fn string_display(&self, f: &mut Formatter) -> VmResult<()> { - self.string_display_with(f, &mut EnvProtocolCaller) + pub fn display_fmt(&self, f: &mut Formatter) -> VmResult<()> { + self.display_fmt_with(f, &mut EnvProtocolCaller) } - /// Internal impl of string_display with a customizable caller. + /// Internal impl of display_fmt with a customizable caller. #[cfg_attr(feature = "bench", inline(never))] - pub(crate) fn string_display_with( + pub(crate) fn display_fmt_with( &self, f: &mut Formatter, caller: &mut dyn ProtocolCaller, @@ -390,7 +390,7 @@ impl Value { let mut args = DynGuardedArgs::new((f,)); let result = - vm_try!(caller.call_protocol_fn(Protocol::STRING_DISPLAY, self.clone(), &mut args)); + vm_try!(caller.call_protocol_fn(Protocol::DISPLAY_FMT, self.clone(), &mut args)); VmResult::Ok(vm_try!(<()>::from_value(result))) } @@ -451,7 +451,7 @@ impl Value { ))) } - /// Debug format the value using the [`STRING_DEBUG`] protocol. + /// Debug format the value using the [`DEBUG_FMT`] protocol. /// /// You must use [`Vm::with`] to specify which virtual machine this function /// is called inside. @@ -462,13 +462,13 @@ impl Value { /// /// This function will panic if called outside of a virtual machine. /// - /// [`STRING_DEBUG`]: Protocol::STRING_DEBUG - pub fn string_debug(&self, f: &mut Formatter) -> VmResult<()> { - self.string_debug_with(f, &mut EnvProtocolCaller) + /// [`DEBUG_FMT`]: Protocol::DEBUG_FMT + pub fn debug_fmt(&self, f: &mut Formatter) -> VmResult<()> { + self.debug_fmt_with(f, &mut EnvProtocolCaller) } - /// Internal impl of string_debug with a customizable caller. - pub(crate) fn string_debug_with( + /// Internal impl of debug_fmt with a customizable caller. + pub(crate) fn debug_fmt_with( &self, f: &mut Formatter, caller: &mut dyn ProtocolCaller, @@ -523,8 +523,7 @@ impl Value { // reborrow f to avoid moving it let mut args = DynGuardedArgs::new((&mut *f,)); - match vm_try!(caller.try_call_protocol_fn(Protocol::STRING_DEBUG, self.clone(), &mut args)) - { + match vm_try!(caller.try_call_protocol_fn(Protocol::DEBUG_FMT, self.clone(), &mut args)) { CallResultOnly::Ok(value) => { vm_try!(<()>::from_value(value)); } @@ -1792,7 +1791,7 @@ impl fmt::Debug for Value { // SAFETY: Formatter does not outlive the string it references. let mut o = unsafe { Formatter::new(NonNull::from(&mut s)) }; - if let Err(e) = self.string_debug(&mut o).into_result() { + if let Err(e) = self.debug_fmt(&mut o).into_result() { match &self.repr { Repr::Empty => { write!(f, "")?; diff --git a/crates/rune/src/runtime/vec.rs b/crates/rune/src/runtime/vec.rs index 19928058a..dc90067c7 100644 --- a/crates/rune/src/runtime/vec.rs +++ b/crates/rune/src/runtime/vec.rs @@ -251,7 +251,7 @@ impl Vec { &self.inner } - pub(crate) fn string_debug_with( + pub(crate) fn debug_fmt_with( this: &[Value], f: &mut Formatter, caller: &mut dyn ProtocolCaller, @@ -260,7 +260,7 @@ impl Vec { vm_try!(vm_write!(f, "[")); while let Some(value) = it.next() { - vm_try!(value.string_debug_with(f, caller)); + vm_try!(value.debug_fmt_with(f, caller)); if it.peek().is_some() { vm_try!(vm_write!(f, ", ")); diff --git a/crates/rune/src/runtime/vm.rs b/crates/rune/src/runtime/vm.rs index 2e1bc1be5..eacacaa92 100644 --- a/crates/rune/src/runtime/vm.rs +++ b/crates/rune/src/runtime/vm.rs @@ -3071,7 +3071,7 @@ impl Vm { let mut f = unsafe { Formatter::new(NonNull::from(&mut s)) }; for value in values { - vm_try!(value.string_display_with(&mut f, &mut *self)); + vm_try!(value.display_fmt_with(&mut f, &mut *self)); } vm_try!(out.store(&mut self.stack, s)); @@ -3678,14 +3678,14 @@ impl Vm { /// Call the provided closure within the context of this virtual machine. /// /// This allows for calling protocol function helpers like - /// [Value::string_display] which requires access to a virtual machine. + /// [Value::display_fmt] which requires access to a virtual machine. /// /// ```no_run /// use rune::{Value, Vm}; /// use rune::runtime::{Formatter, VmError}; /// /// fn use_with(vm: &Vm, output: &Value, f: &mut Formatter) -> Result<(), VmError> { - /// vm.with(|| output.string_display(f)).into_result()?; + /// vm.with(|| output.display_fmt(f)).into_result()?; /// Ok(()) /// } /// ``` diff --git a/crates/rune/src/tests.rs b/crates/rune/src/tests.rs index a7852e9cf..75702c9ec 100644 --- a/crates/rune/src/tests.rs +++ b/crates/rune/src/tests.rs @@ -430,6 +430,7 @@ mod compiler_warnings; mod continue_; mod core_macros; mod custom_macros; +mod debug_fmt; mod deprecation; mod derive_from_to_value; mod destructuring; @@ -450,7 +451,6 @@ mod range; mod reference_error; mod rename_type; mod result; -mod string_debug; mod tuple; mod type_name_native; mod unit_constants; diff --git a/crates/rune/src/tests/string_debug.rs b/crates/rune/src/tests/debug_fmt.rs similarity index 84% rename from crates/rune/src/tests/string_debug.rs rename to crates/rune/src/tests/debug_fmt.rs index 3eb043c32..7a02902d8 100644 --- a/crates/rune/src/tests/string_debug.rs +++ b/crates/rune/src/tests/debug_fmt.rs @@ -7,8 +7,8 @@ prelude!(); pub struct NativeStructWithProtocol; impl NativeStructWithProtocol { - #[rune::function(protocol = STRING_DEBUG)] - fn string_debug(&self, f: &mut Formatter) -> VmResult<()> { + #[rune::function(protocol = DEBUG_FMT)] + fn debug_fmt(&self, f: &mut Formatter) -> VmResult<()> { vm_write!(f, "{self:?}") } } @@ -20,14 +20,14 @@ pub struct NativeStructWithoutProtocol; fn make_native_module() -> Result { let mut module = Module::with_crate("native_crate")?; module.ty::()?; - module.function_meta(NativeStructWithProtocol::string_debug)?; + module.function_meta(NativeStructWithProtocol::debug_fmt)?; module.ty::()?; Ok(module) } #[test] -fn test_with_string_debug() { +fn test_with_debug_fmt() { let t1 = NativeStructWithProtocol; assert_eq!( rune_n! { @@ -41,7 +41,7 @@ fn test_with_string_debug() { } #[test] -fn test_without_string_debug() { +fn test_without_debug_fmt() { let t1 = NativeStructWithoutProtocol; let result = rune_n! { make_native_module().expect("failed making native module"), diff --git a/site/content/posts/2020-10-19-tmir1.md b/site/content/posts/2020-10-19-tmir1.md index 645782693..3eb48d253 100644 --- a/site/content/posts/2020-10-19-tmir1.md +++ b/site/content/posts/2020-10-19-tmir1.md @@ -259,7 +259,7 @@ To accomplish this, `FormatArgs` is actually expanded into two internal macros: * `#[builtin] template!(..)` which is the same macro produced by template strings. * `#[builtin] format!(..)` which produces a `Format` value that conveniently - implements [the `STRING_DISPLAY` protocol]. + implements [the `DISPLAY_FMT` protocol]. Strictly speaking, these expansions result in valid Rune. The `#[builtin]` attribute modifies how the macros are looked up so that they are solely expanded @@ -288,7 +288,7 @@ This also means that the following macros now also support formatting: * `assert!` and `assert_eq!`. * The newly introduced `format!`, which produces a string directly. -[the `STRING_DISPLAY` protocol]: https://rune-rs.github.io/book/template_literals.html#the-string_display-protocol +[the `DISPLAY_FMT` protocol]: https://rune-rs.github.io/book/template_literals.html#the-display_fmt-protocol ## constant evaluation