home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.os.vms      DEC's VAX* line of computers & VMS.      264,096 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 263,789 of 264,096   
   =?UTF-8?Q?Arne_Vajh=C3=B8j?= to Dan Cross   
   Re: Unsafe code blocks   
   18 Nov 25 14:04:56   
   
   From: arne@vajhoej.dk   
      
   On 11/15/2025 9:16 PM, Dan Cross wrote:   
   >> Also note the availability of the 'Valid attribute to make sure that what   
   >> is in the variable after the unsafe conversion is actually a valid value.   
   >   
   > Sum types make this trivial:   
   >   
   >      impl SomeType {   
   >          fn try_from(i: i32) -> Option {   
   >              // if valid, return `Some(whatever`),   
   >              // else return `None`.   
   >          }   
   >      }   
   (assuming Option in Rust is what it is in other languages)   
      
   Option and Ada Valid are somewhat different.   
      
   Option is a way for a function/method to either return   
   a value or return the fact that there is no value.   
      
   A much better way to do that than traditional   
   return null or -1 or whatever to indicate there   
   is no value.   
      
   Ada valid attribute is a runtime check on the result from   
   an unsafe conversion to see if it meets the constraints   
   of the data type.   
      
   Arne   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca