-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
141 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/*pub fn incr_u32(x: u32) -> u32 { | ||
x + 1 | ||
} | ||
/* | ||
/* Testing function pointers and closures */ | ||
// TODO: this requires to take into account the constraints over associated types | ||
// because the output type of the Fn trait is an associated type, not a parameter. | ||
// More precisely, we have the constraint that: | ||
// <F as Fn<T>>::Output = T | ||
#[allow(clippy::manual_map)] | ||
pub fn map_option<T, F>(x: Option<T>, f: F) -> Option<T> | ||
where | ||
F: Fn(T) -> T, | ||
{ | ||
match x { | ||
None => None, | ||
Some(x) => Some(f(x)), | ||
} | ||
} | ||
*/ | ||
// With a pointer to a top level function | ||
pub fn test_map_option1(x: Option<u32>) -> Option<u32> { | ||
map_option(x, incr_u32) | ||
} | ||
*/ | ||
|
||
/* | ||
// | ||
pub fn test_closure1<T>(x: &T) -> &T { | ||
//let f: fn(&T) -> &T = |x| x; | ||
let f: fn(u32) -> u32 = |x| x; | ||
//(f)(x) | ||
x | ||
} | ||
*/ | ||
|
||
/* | ||
// With a local function | ||
pub fn test_map_option2(x: Option<u32>) -> Option<u32> { | ||
let f: fn(u32) -> u32 = |x| x + 1; | ||
map_option(x, f) | ||
} | ||
/* | ||
// With a local function which uses local type variables | ||
pub fn test_map_option3<T, U>(_: T, x: Option<U>) -> Option<U> { | ||
let f: fn(U) -> U = |x| x; | ||
map_option(x, f) | ||
} | ||
*/ | ||
/*// With a `dyn` | ||
pub fn test_map_option3(x: Option<u32>) -> Option<u32> { | ||
let f: fn(u32) -> u32 = |x| x + 1; | ||
map_option(x, f) | ||
}*/ | ||
/* | ||
pub fn map(x: [i32; 256]) -> [i32; 256] { | ||
x.map(|v| v) | ||
} | ||
*/ | ||
*/ | ||
|
||
/* | ||
macro_rules! impl_generic_struct { | ||
($name:ident) => { | ||
pub struct $name<const SIZE: usize> { | ||
pub value: [u8; SIZE], | ||
} | ||
impl<const SIZE: usize> TryFrom<&[u8]> for $name<SIZE> { | ||
type Error = core::array::TryFromSliceError; | ||
fn try_from(value: &[u8]) -> Result<Self, Self::Error> { | ||
match value.try_into() { | ||
Ok(value) => Ok(Self { value }), | ||
Err(e) => Err(e), | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
impl_generic_struct!(KyberCiphertext); | ||
*/ | ||
|
||
/* | ||
use std::convert::{TryFrom, TryInto}; | ||
pub struct KyberCypherText<const SIZE: usize> { | ||
pub value: [u8; SIZE], | ||
} | ||
impl<const SIZE: usize> TryFrom<&[u8]> for KyberCypherText<SIZE> { | ||
type Error = core::array::TryFromSliceError; | ||
fn try_from(value: &[u8]) -> Result<Self, Self::Error> { | ||
match value.try_into() { | ||
Ok(value) => Ok(Self { value }), | ||
Err(e) => Err(e), | ||
} | ||
} | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// The example below (in particular the impl block) is peculiar with regards | ||
// to the treatment of regions. In particular, when we translate the implementation | ||
// of `from` to LLBC, we get something which looks like this: | ||
// ``` | ||
// | ||
// fn crate::{bool}::from<@R0, @R1>(@1: &@R1 (bool)) -> | ||
// core::result::Result<bool, crate::{bool}<@R0>::Error> { | ||
// // ^^^ | ||
// // HERE | ||
// ... // omitted | ||
// } | ||
// ``` | ||
pub trait From<T> { | ||
type Error; | ||
fn from(v: T) -> Result<Self, Self::Error> | ||
where | ||
Self: std::marker::Sized; | ||
} | ||
|
||
impl From<&bool> for bool { | ||
type Error = (); | ||
|
||
fn from(v: &bool) -> Result<Self, Self::Error> { | ||
Ok(*v) | ||
} | ||
} |