11//! Prelude extension - available in all contexts, defining common types,
22//! operations and constants.
3+ use std:: str:: FromStr ;
34use std:: sync:: { Arc , Weak } ;
45
56use itertools:: Itertools ;
@@ -447,14 +448,19 @@ impl CustomConst for ConstUsize {
447448}
448449
449450#[ derive( Debug , Clone , PartialEq , Hash , serde:: Serialize , serde:: Deserialize ) ]
450- /// Structure for holding constant usize values.
451+ /// Structure for holding constant [error types].
452+ ///
453+ /// [error types]: crate::extension::prelude::error_type
451454pub struct ConstError {
452455 /// Integer tag/signal for the error.
453456 pub signal : u32 ,
454457 /// Error message.
455458 pub message : String ,
456459}
457460
461+ /// Default error signal.
462+ pub const DEFAULT_ERROR_SIGNAL : u32 = 1 ;
463+
458464impl ConstError {
459465 /// Define a new error value.
460466 pub fn new ( signal : u32 , message : impl ToString ) -> Self {
@@ -464,6 +470,12 @@ impl ConstError {
464470 }
465471 }
466472
473+ /// Define a new error value with the [default signal].
474+ ///
475+ /// [default signal]: DEFAULT_ERROR_SIGNAL
476+ pub fn new_default_signal ( message : impl ToString ) -> Self {
477+ Self :: new ( DEFAULT_ERROR_SIGNAL , message)
478+ }
467479 /// Returns an "either" value with a failure variant.
468480 ///
469481 /// args:
@@ -491,6 +503,20 @@ impl CustomConst for ConstError {
491503 }
492504}
493505
506+ impl FromStr for ConstError {
507+ type Err = ( ) ;
508+
509+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
510+ Ok ( Self :: new_default_signal ( s) )
511+ }
512+ }
513+
514+ impl From < String > for ConstError {
515+ fn from ( s : String ) -> Self {
516+ Self :: new_default_signal ( s)
517+ }
518+ }
519+
494520#[ derive( Debug , Clone , PartialEq , Eq , Hash , serde:: Serialize , serde:: Deserialize ) ]
495521/// A structure for holding references to external symbols.
496522pub struct ConstExternalSymbol {
0 commit comments