Change doc comments to rustdoc in bool.rs
This commit is contained in:
parent
2c70b2fb7e
commit
350e87eaae
|
@ -1,96 +1,89 @@
|
|||
// -*- rust -*-
|
||||
|
||||
/*
|
||||
Module: bool
|
||||
|
||||
Classic Boolean logic reified as ADT
|
||||
*/
|
||||
#[doc = "Classic Boolean logic reified as ADT"];
|
||||
|
||||
export t;
|
||||
export not, and, or, xor, implies;
|
||||
export eq, ne, is_true, is_false;
|
||||
export from_str, to_str, all_values, to_bit;
|
||||
|
||||
/*
|
||||
Type: t
|
||||
|
||||
The type of boolean logic values
|
||||
*/
|
||||
#[doc = "The type of boolean logic values"]
|
||||
type t = bool;
|
||||
|
||||
/* Function: not
|
||||
|
||||
Negation/Inverse
|
||||
*/
|
||||
#[doc(
|
||||
brief = "Negation/Inverse",
|
||||
args(v = "Value to Negate/Invert"),
|
||||
return = "Negated/Inverted Value"
|
||||
)]
|
||||
pure fn not(v: t) -> t { !v }
|
||||
|
||||
/* Function: and
|
||||
|
||||
Conjunction
|
||||
*/
|
||||
#[doc(
|
||||
brief = "Conjunction",
|
||||
args(a = "value `a`",
|
||||
b = "value `b`"),
|
||||
return = "`a` AND `b`"
|
||||
)]
|
||||
pure fn and(a: t, b: t) -> t { a && b }
|
||||
|
||||
/* Function: or
|
||||
|
||||
Disjunction
|
||||
*/
|
||||
#[doc(
|
||||
brief = "Disjunction",
|
||||
args(a = "value `a`",
|
||||
b = "value `b`"),
|
||||
return = "`a` OR `b`"
|
||||
)]
|
||||
pure fn or(a: t, b: t) -> t { a || b }
|
||||
|
||||
/*
|
||||
Function: xor
|
||||
|
||||
Exclusive or, i.e. `or(and(a, not(b)), and(not(a), b))`
|
||||
*/
|
||||
#[doc(
|
||||
brief = "Exclusive or, i.e. `or(and(a, not(b)), and(not(a), b))`",
|
||||
args(a = "value `a`",
|
||||
b = "value `b`"),
|
||||
return = "`a` XOR `b`"
|
||||
)]
|
||||
pure fn xor(a: t, b: t) -> t { (a && !b) || (!a && b) }
|
||||
|
||||
/*
|
||||
Function: implies
|
||||
|
||||
Implication in the logic, i.e. from `a` follows `b`
|
||||
*/
|
||||
#[doc(
|
||||
brief = "Implication in the logic, i.e. from `a` follows `b`",
|
||||
args(a = "value `a`",
|
||||
b = "value `b`"),
|
||||
return = "`a` IMPLIES `b`"
|
||||
)]
|
||||
pure fn implies(a: t, b: t) -> t { !a || b }
|
||||
|
||||
/*
|
||||
Predicate: eq
|
||||
|
||||
Returns:
|
||||
|
||||
true if truth values `a` and `b` are indistinguishable in the logic
|
||||
*/
|
||||
#[doc(
|
||||
brief = "true if truth values `a` and `b` are indistinguishable in the logic",
|
||||
args(a = "value `a`",
|
||||
b = "value `b`"),
|
||||
return = "`a` == `b`"
|
||||
)]
|
||||
pure fn eq(a: t, b: t) -> bool { a == b }
|
||||
|
||||
/*
|
||||
Predicate: ne
|
||||
|
||||
Returns:
|
||||
|
||||
true if truth values `a` and `b` are distinguishable in the logic
|
||||
*/
|
||||
#[doc(
|
||||
brief = "true if truth values `a` and `b` are distinguishable in the logic",
|
||||
args(a = "value `a`",
|
||||
b = "value `b`"),
|
||||
return = "`a` != `b`"
|
||||
)]
|
||||
pure fn ne(a: t, b: t) -> bool { a != b }
|
||||
|
||||
/*
|
||||
Predicate: is_true
|
||||
|
||||
Returns:
|
||||
|
||||
true if `v` represents truth in the logic
|
||||
*/
|
||||
#[doc(
|
||||
brief = "true if `v` represents truth in the logic",
|
||||
args(v = "value `v`"),
|
||||
return = "bool(`v`)"
|
||||
)]
|
||||
pure fn is_true(v: t) -> bool { v }
|
||||
|
||||
/*
|
||||
Predicate: is_false
|
||||
|
||||
Returns:
|
||||
|
||||
true if `v` represents falsehood in the logic
|
||||
*/
|
||||
#[doc(
|
||||
brief = "true if `v` represents falsehood in the logic",
|
||||
args(v = "value `v`"),
|
||||
return = "bool(!`v`)"
|
||||
)]
|
||||
pure fn is_false(v: t) -> bool { !v }
|
||||
|
||||
/*
|
||||
Function: from_str
|
||||
|
||||
Parse logic value from `s`
|
||||
*/
|
||||
#[doc(
|
||||
brief = "Parse logic value from `s`",
|
||||
args(v = "string value `s`"),
|
||||
return = "true if `s` equals \"true\", else false"
|
||||
)]
|
||||
pure fn from_str(s: str) -> t {
|
||||
alt s {
|
||||
"true" { true }
|
||||
|
@ -98,31 +91,28 @@ pure fn from_str(s: str) -> t {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: to_str
|
||||
|
||||
Convert `v` into a string
|
||||
*/
|
||||
#[doc(
|
||||
brief = "Convert `v` into a string",
|
||||
args(v = "truth value `v`"),
|
||||
return = "\"true\" if value `v` is true, else \"false\""
|
||||
)]
|
||||
pure fn to_str(v: t) -> str { if v { "true" } else { "false" } }
|
||||
|
||||
/*
|
||||
Function: all_values
|
||||
|
||||
Iterates over all truth values by passing them to `blk`
|
||||
in an unspecified order
|
||||
*/
|
||||
#[doc(
|
||||
brief = "Iterates over all truth values by passing them to `blk` in an unspecified order",
|
||||
args(v = "block value `v`"),
|
||||
return = "Undefined return value"
|
||||
)]
|
||||
fn all_values(blk: block(v: t)) {
|
||||
blk(true);
|
||||
blk(false);
|
||||
}
|
||||
|
||||
/*
|
||||
Function: to_bit
|
||||
|
||||
Returns:
|
||||
|
||||
An u8 whose first bit is set if `if_true(v)` holds
|
||||
*/
|
||||
#[doc(
|
||||
brief = "converts truth value to an 8 bit byte",
|
||||
args(v = "value `v`"),
|
||||
return = "returns byte with value 1 if `v` has truth value of true, else 0"
|
||||
)]
|
||||
pure fn to_bit(v: t) -> u8 { if v { 1u8 } else { 0u8 } }
|
||||
|
||||
// Local Variables:
|
||||
|
|
Loading…
Reference in New Issue