From 690ba52c67fc5213f74041a33151503a896caefc Mon Sep 17 00:00:00 2001 From: Luca Fulchir Date: Fri, 16 Feb 2024 19:08:03 +0100 Subject: [PATCH] Failed trait inheritance test Signed-off-by: Luca Fulchir --- bok/src/conf/mod.rs | 25 ++++++++++++++++ bok/src/libt/mod.rs | 65 +++++++++++++++++++++++++++++++++++++++++ bok/src/main.rs | 18 +++++++++++- bok/src/pkgs/mod.rs | 67 +++++++++++++++++++++++++++++++++++++++++++ bok/src/pkgs/one.rs | 31 ++++++++++++++++++++ bok/src/pkgs/three.rs | 30 +++++++++++++++++++ bok/src/pkgs/two.rs | 30 +++++++++++++++++++ bokmacro/Cargo.toml | 9 ++++++ bokmacro/src/lib.rs | 28 ++++++++++++++++++ 9 files changed, 302 insertions(+), 1 deletion(-) create mode 100644 bok/src/conf/mod.rs create mode 100644 bok/src/libt/mod.rs create mode 100644 bok/src/pkgs/mod.rs create mode 100644 bok/src/pkgs/one.rs create mode 100644 bok/src/pkgs/three.rs create mode 100644 bok/src/pkgs/two.rs create mode 100644 bokmacro/Cargo.toml create mode 100644 bokmacro/src/lib.rs diff --git a/bok/src/conf/mod.rs b/bok/src/conf/mod.rs new file mode 100644 index 0000000..0f34141 --- /dev/null +++ b/bok/src/conf/mod.rs @@ -0,0 +1,25 @@ +/* + * Copyright 2024 Luca Fulchir + * + * 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 {}; +} +*/ diff --git a/bok/src/libt/mod.rs b/bok/src/libt/mod.rs new file mode 100644 index 0000000..5bed5c9 --- /dev/null +++ b/bok/src/libt/mod.rs @@ -0,0 +1,65 @@ +/* + * Copyright 2024 Luca Fulchir + * + * 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 { + /// Set, only once per + Set(T), + /// Delete a value + Del(T), +} +pub enum ValueList { + /// Set, only once per + Set(T), + /// Delete a value + Del(T), + /// Add to a list + Add(T), + /// Merge (add + dedup) + Merge(T), +} +*/ diff --git a/bok/src/main.rs b/bok/src/main.rs index ac27709..68bf215 100644 --- a/bok/src/main.rs +++ b/bok/src/main.rs @@ -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!("{}", ::one().my_attr); + println!("{}", ::two().my_attr); + println!("{}", Pkgs2::three().my_attr); } diff --git a/bok/src/pkgs/mod.rs b/bok/src/pkgs/mod.rs new file mode 100644 index 0000000..f683b04 --- /dev/null +++ b/bok/src/pkgs/mod.rs @@ -0,0 +1,67 @@ +/* + * Copyright 2024 Luca Fulchir + * + * 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 Pkgs1Pkgs for Pkgs1 {} +impl 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 Pkgs2Pkgs for Pkgs2 {} +impl Pkgs2NewPkgs for Pkgs2 {} +impl Pkgs1NewPkgs for Pkgs2 {} diff --git a/bok/src/pkgs/one.rs b/bok/src/pkgs/one.rs new file mode 100644 index 0000000..bc5a928 --- /dev/null +++ b/bok/src/pkgs/one.rs @@ -0,0 +1,31 @@ +/* + * Copyright 2024 Luca Fulchir + * + * 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 } + } +} diff --git a/bok/src/pkgs/three.rs b/bok/src/pkgs/three.rs new file mode 100644 index 0000000..b65da2e --- /dev/null +++ b/bok/src/pkgs/three.rs @@ -0,0 +1,30 @@ +/* + * Copyright 2024 Luca Fulchir + * + * 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 } + } +} diff --git a/bok/src/pkgs/two.rs b/bok/src/pkgs/two.rs new file mode 100644 index 0000000..4f46cc2 --- /dev/null +++ b/bok/src/pkgs/two.rs @@ -0,0 +1,30 @@ +/* + * Copyright 2024 Luca Fulchir + * + * 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 } + } +} diff --git a/bokmacro/Cargo.toml b/bokmacro/Cargo.toml new file mode 100644 index 0000000..cae761d --- /dev/null +++ b/bokmacro/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "bokmacro" +version = "0.1.0" +edition = "2021" + +[lib] +proc-macro = true + +[dependencies] diff --git a/bokmacro/src/lib.rs b/bokmacro/src/lib.rs new file mode 100644 index 0000000..2c7baea --- /dev/null +++ b/bokmacro/src/lib.rs @@ -0,0 +1,28 @@ +/* + * Copyright 2024 Luca Fulchir + * + * 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::*; + )* + }; +} +*/