From 1c89c6be4f3c9755c669db70e1d84cd57d3701ef Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 10 Feb 2022 08:31:41 +0800 Subject: [PATCH] Doc fixes. --- src/reify.rs | 16 ++++++++++++---- src/types/parse_error.rs | 3 +-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/reify.rs b/src/reify.rs index e582b5cb..bdbe2db8 100644 --- a/src/reify.rs +++ b/src/reify.rs @@ -1,12 +1,19 @@ -/// Runs `$code` if `$old` is of type `$t`. +/// Macro to cast an identifier or expression to another type with type checks. /// -/// This macro is primarily used for type casting between known types. +/// Runs _code_ if _variable_ or _expression_ is of type _type_, otherwise run _fallback_. +/// +/// # Syntax +/// +/// * `reify!(`_variable_ or _expression_`,|`_temp-variable_`: `_type_`|` _code_`,` `||` _fallback_ `)` +/// * `reify!(`_variable_ or _expression_`,|`_temp-variable_`: `_type_`|` _code_ `)` +/// * `reify!(`_variable_ or _expression_ `=>` `Option<`_type_`>` `)` +/// * `reify!(`_variable_ or _expression_ `=>` _type_ `)` #[macro_export] macro_rules! reify { ($old:ident, |$new:ident : $t:ty| $code:expr, || $fallback:expr) => {{ if std::any::TypeId::of::<$t>() == std::any::Any::type_id(&$old) { - // SAFETY: This is safe because we check to make sure the two types are - // actually the same type. + // SAFETY: This is safe because we already checked to make sure the two types + // are actually the same. let $new: $t = unsafe { std::mem::transmute_copy(&std::mem::ManuallyDrop::new($old)) }; $code } else { @@ -17,6 +24,7 @@ macro_rules! reify { let old = $old; reify!(old, |$new: $t| $code, || $fallback) }}; + ($old:ident, |$new:ident : $t:ty| $code:expr) => { reify!($old, |$new: $t| $code, || ()) }; diff --git a/src/types/parse_error.rs b/src/types/parse_error.rs index 8f129676..7d5835ec 100644 --- a/src/types/parse_error.rs +++ b/src/types/parse_error.rs @@ -10,8 +10,7 @@ use std::fmt; #[cfg(feature = "no_std")] use std::prelude::v1::*; -/// _(internals)_ Error encountered when tokenizing the script text. -/// Exported under the `internals` feature only. +/// Error encountered when tokenizing the script text. #[derive(Debug, Eq, PartialEq, Clone, Hash)] #[non_exhaustive] pub enum LexError {