Failed trait inheritance test

Signed-off-by: Luca Fulchir <luca.fulchir@runesauth.com>
This commit is contained in:
Luca Fulchir 2024-02-16 19:08:03 +01:00
parent 0c6b1a1052
commit 690ba52c67
Signed by: luca.fulchir
GPG Key ID: 8F6440603D13A78E
9 changed files with 302 additions and 1 deletions

25
bok/src/conf/mod.rs Normal file
View File

@ -0,0 +1,25 @@
/*
* Copyright 2024 Luca Fulchir <luca.fulchir@runesauth.com>
*
* Licensed under the Apache License, Version 2.0 with LLVM exception (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License and of the exception at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://spdx.org/licenses/LLVM-exception.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
use crate::libt;
static CONF: libt::Conf = libt::Conf {};
mod conf {
use crate::libt;
static CONF: libt::Conf = libt::Conf {};
}
*/

65
bok/src/libt/mod.rs Normal file
View File

@ -0,0 +1,65 @@
/*
* Copyright 2024 Luca Fulchir <luca.fulchir@runesauth.com>
*
* Licensed under the Apache License, Version 2.0 with LLVM exception (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License and of the exception at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://spdx.org/licenses/LLVM-exception.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use ::std::any::Any;
// Package stuff
#[macro_export]
macro_rules! moduse {
($($name:ident)*) => {
$(
mod $name;
#[allow(unused_imports)]
use $name::*;
)*
};
}
pub use moduse;
pub trait PkgList {}
pub trait Pkg: Any {
fn as_any(&self) -> &dyn Any
where
Self: Sized,
{
self
}
}
// Conf stuff
/*
pub struct Conf {}
pub enum Value<T: Sized> {
/// Set, only once per
Set(T),
/// Delete a value
Del(T),
}
pub enum ValueList<T: Sized> {
/// Set, only once per
Set(T),
/// Delete a value
Del(T),
/// Add to a list
Add(T),
/// Merge (add + dedup)
Merge(T),
}
*/

View File

@ -15,6 +15,22 @@
* limitations under the License.
*/
mod conf;
mod libt;
mod pkgs;
fn main() {
println!("Hello, world!");
use pkgs::Pkgs1NewPkgs;
use pkgs::Pkgs1Pkgs;
let pkgs1 = pkgs::Pkgs1 {};
use pkgs::Pkgs2NewPkgs;
use pkgs::Pkgs2Pkgs;
let pkgs2 = pkgs::Pkgs2 {};
use pkgs::*;
println!("{}", Pkgs1::one().my_attr);
println!("{}", Pkgs1::two().my_attr);
println!("{}", <Pkgs2 as Pkgs1NewPkgs>::one().my_attr);
println!("{}", <Pkgs2 as Pkgs2NewPkgs>::two().my_attr);
println!("{}", Pkgs2::three().my_attr);
}

67
bok/src/pkgs/mod.rs Normal file
View File

@ -0,0 +1,67 @@
/*
* Copyright 2024 Luca Fulchir <luca.fulchir@runesauth.com>
*
* Licensed under the Apache License, Version 2.0 with LLVM exception (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License and of the exception at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://spdx.org/licenses/LLVM-exception.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::libt;
//use ::std::{boxed::Box, vec::Vec};
crate::libt::moduse! {
one
two
three
}
///
/// This is a Package List
///
/// eventually all this will be replaced by macros
pub struct Pkgs1 {}
pub trait Pkgs1NewPkgs {
fn one() -> One {
One::new()
}
fn two() -> Two {
Two::new()
}
}
pub trait Pkgs1Pkgs: Pkgs1NewPkgs + libt::PkgList {}
impl Pkgs1NewPkgs for Pkgs1 {}
//impl<Pkgs1: Pkgs1NewPkgs + libt::PkgList> Pkgs1Pkgs for Pkgs1 {}
impl<Pkgs1: Pkgs1NewPkgs + libt::PkgList> Pkgs1Pkgs for Pkgs1 {}
///
/// This is a Package List that extends and changes Pkgs1
///
/// eventually all this will be replaced by macros
pub struct Pkgs2 {}
pub trait Pkgs2NewPkgs {
fn two() -> Two {
let mut t = Two::new();
t.my_attr = 42;
t
}
fn three() -> Three {
Three::new()
}
}
pub trait Pkgs2Pkgs: Pkgs2NewPkgs + Pkgs1Pkgs {}
impl<Pkgs2: Pkgs2NewPkgs + Pkgs1Pkgs> Pkgs2Pkgs for Pkgs2 {}
impl Pkgs2NewPkgs for Pkgs2 {}
impl Pkgs1NewPkgs for Pkgs2 {}

31
bok/src/pkgs/one.rs Normal file
View File

@ -0,0 +1,31 @@
/*
* Copyright 2024 Luca Fulchir <luca.fulchir@runesauth.com>
*
* Licensed under the Apache License, Version 2.0 with LLVM exception (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License and of the exception at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://spdx.org/licenses/LLVM-exception.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::libt;
//use ::std::boxed::Box;
pub struct One {
pub my_attr: u32,
}
impl libt::Pkg for One {}
impl One {
pub fn new() -> Self {
One { my_attr: 1 }
}
}

30
bok/src/pkgs/three.rs Normal file
View File

@ -0,0 +1,30 @@
/*
* Copyright 2024 Luca Fulchir <luca.fulchir@runesauth.com>
*
* Licensed under the Apache License, Version 2.0 with LLVM exception (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License and of the exception at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://spdx.org/licenses/LLVM-exception.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::libt;
pub struct Three {
pub my_attr: u32,
}
impl libt::Pkg for Three {}
impl Three {
pub fn new() -> Self {
Three { my_attr: 42 }
}
}

30
bok/src/pkgs/two.rs Normal file
View File

@ -0,0 +1,30 @@
/*
* Copyright 2024 Luca Fulchir <luca.fulchir@runesauth.com>
*
* Licensed under the Apache License, Version 2.0 with LLVM exception (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License and of the exception at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://spdx.org/licenses/LLVM-exception.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::libt;
pub struct Two {
pub my_attr: u32,
}
impl libt::Pkg for Two {}
impl Two {
pub fn new() -> Self {
Two { my_attr: 2 }
}
}

9
bokmacro/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "bokmacro"
version = "0.1.0"
edition = "2021"
[lib]
proc-macro = true
[dependencies]

28
bokmacro/src/lib.rs Normal file
View File

@ -0,0 +1,28 @@
/*
* Copyright 2024 Luca Fulchir <luca.fulchir@runesauth.com>
*
* Licensed under the Apache License, Version 2.0 with LLVM exception (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License and of the exception at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://spdx.org/licenses/LLVM-exception.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
macro_rules! moduse {
($(mod $name:ident;)*) => {
$(
mod $name;
#[allow(unused_imports)]
use $name::*;
)*
};
}
*/