This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
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
3 changed files
with
95 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#![crate_type = "lib"] | ||
|
||
use std::marker::PhantomData; | ||
pub trait Allocator<R> { | ||
type Buffer; | ||
} | ||
pub struct DefaultAllocator; | ||
impl <R> Allocator<R> for DefaultAllocator { | ||
type Buffer = (); | ||
} | ||
pub type Owned<R> = <DefaultAllocator as Allocator<R>>::Buffer; | ||
pub type MatrixMN<R> = Matrix<R, Owned<R>>; | ||
pub type Matrix4<N> = Matrix<N, ()>; | ||
pub struct Matrix<R, S> { | ||
pub data: S, | ||
_phantoms: PhantomData<R>, | ||
} | ||
pub fn set_object_transform(matrix: &Matrix4<()>) { | ||
matrix.js_buffer_view(); | ||
} | ||
pub trait Storable { | ||
type Cell; | ||
fn slice_to_items(_buffer: &()) -> &[Self::Cell] { | ||
unimplemented!() | ||
} | ||
} | ||
pub type Cell<T> = <T as Storable>::Cell; | ||
impl<R> Storable for MatrixMN<R> | ||
where | ||
DefaultAllocator: Allocator<R>, | ||
{ | ||
type Cell = (); | ||
} | ||
pub trait JsBufferView { | ||
fn js_buffer_view(&self) -> usize { | ||
unimplemented!() | ||
} | ||
} | ||
impl<R> JsBufferView for [MatrixMN<R>] | ||
where | ||
DefaultAllocator: Allocator<R>, | ||
MatrixMN<R>: Storable, | ||
[Cell<MatrixMN<R>>]: JsBufferView, | ||
{ | ||
fn js_buffer_view(&self) -> usize { | ||
<MatrixMN<R> as Storable>::slice_to_items(&()).js_buffer_view() | ||
} | ||
} | ||
impl JsBufferView for [()] {} | ||
impl<R> JsBufferView for MatrixMN<R> where DefaultAllocator: Allocator<R> {} |
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,31 @@ | ||
#![feature(const_generics, const_evaluatable_checked)] | ||
#![allow(incomplete_features)] | ||
|
||
trait Melon<const X: usize> { | ||
fn new(arr: [i32; X]) -> Self; | ||
fn change<T: Melon<X>>(self) -> T; | ||
} | ||
|
||
struct Foo([i32; 5]); | ||
struct Bar<const A: usize, const B: usize>([i32; A + B]) | ||
where [(); A + B]: ; | ||
|
||
impl Melon<5> for Foo { | ||
fn new(arr: [i32; 5]) -> Self { | ||
Foo(arr) | ||
} | ||
fn change<T: Melon<5>>(self) -> T { | ||
T::new(self.0) | ||
} | ||
} | ||
|
||
impl<const A: usize, const B: usize> Melon<{A + B}> for Bar<A, B> | ||
where [(); A + B]: , | ||
{ | ||
fn new(arr: [i32; A + B]) -> Self { | ||
Bar(arr) | ||
} | ||
fn change<T: Melon<{A + B}>>(self) -> T { | ||
T::new(self.0) | ||
} | ||
} |
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,14 @@ | ||
#![crate_type = "lib"] | ||
use std::path::Path; | ||
struct A { | ||
pub func: fn(check: bool, a: &Path, b: Option<&Path>), | ||
} | ||
const MY_A: A = A { | ||
func: |check, a, b| { | ||
if check { | ||
let _ = (); | ||
} else if let Some(parent) = b.and_then(|p| p.parent()) { | ||
let _ = (); | ||
} | ||
}, | ||
}; |