Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions crates/cgp-extra/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

pub mod prelude;

pub use {
cgp_dispatch as dispatch, cgp_error_extra as error, cgp_field_extra as field,
cgp_handler as handler, cgp_monad as monad, cgp_run as run, cgp_runtime as runtime,
};
pub use cgp_dispatch as dispatch;
pub use cgp_error_extra as error;
pub use cgp_field_extra as field;
pub use cgp_handler as handler;
pub use cgp_monad as monad;
pub use cgp_run as run;
pub use cgp_runtime as runtime;
3 changes: 2 additions & 1 deletion crates/cgp-field/src/types/product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ pub struct π<Head, Tail>(pub Head, pub Tail);
#[allow(non_camel_case_types)]
pub struct ε;

pub use {ε as Nil, π as Cons};
pub use ε as Nil;
pub use π as Cons;
3 changes: 2 additions & 1 deletion crates/cgp-field/src/types/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ pub enum σ<Head, Tail> {
#[derive(Eq, PartialEq, Debug, Clone)]
pub enum θ {}

pub use {θ as Void, σ as Either};
pub use θ as Void;
pub use σ as Either;
2 changes: 1 addition & 1 deletion crates/cgp-macro-lib/src/derive_getter/getter_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub enum FieldMode {
OptionRef,
MRef,
Str,
Clone,
Copy,
Slice,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/cgp-macro-lib/src/derive_getter/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub fn extend_call_expr(
}
}
}
FieldMode::Clone => {
FieldMode::Copy => {
quote! {
#call_expr .clone()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cgp-macro-lib/src/derive_getter/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ pub fn parse_field_type(
} else if let (Some(field_type), None) = (try_parse_mref(type_path), receiver_mut) {
Ok((field_type.clone(), FieldMode::MRef))
} else {
Ok((return_type.clone(), FieldMode::Clone))
Ok((return_type.clone(), FieldMode::Copy))
}
}
_ => Err(Error::new(
Expand Down
2 changes: 1 addition & 1 deletion crates/cgp-tests/tests/cgp_fn_tests/extend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn rectangle_area(
#[implicit] height: Self::Scalar,
) -> Self::Scalar
where
Self::Scalar: Mul<Output = Self::Scalar> + Clone,
Self::Scalar: Mul<Output = Self::Scalar> + Copy,
{
width * height
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cgp-tests/tests/cgp_fn_tests/foreign_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn rectangle_area<Types: HasScalarType>(
#[implicit] height: Scalar,
) -> Scalar
where
Scalar: Mul<Output = Scalar> + Clone,
Scalar: Mul<Output = Scalar> + Copy,
{
let res: Scalar = width * height;
res
Expand Down
2 changes: 1 addition & 1 deletion crates/cgp-tests/tests/cgp_fn_tests/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn rectangle_area<Scalar>(
#[implicit] height: Scalar,
) -> Scalar
where
Scalar: Mul<Output = Scalar> + Clone,
Scalar: Mul<Output = Scalar> + Copy,
{
width * height
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cgp-tests/tests/cgp_fn_tests/nested_foreign_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub trait HasTypes {
#[extend_where(Types: HasScalarType)]
pub fn rectangle_area(&self, #[implicit] width: Scalar, #[implicit] height: Scalar) -> Scalar
where
Scalar: Mul<Output = Scalar> + Clone,
Scalar: Mul<Output = Scalar> + Copy,
{
let res: Scalar = width * height;
res
Expand Down
2 changes: 1 addition & 1 deletion crates/cgp-tests/tests/cgp_fn_tests/use_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cgp::prelude::*;

#[cgp_type]
pub trait HasScalarType {
type Scalar: Mul<Output = Self::Scalar> + Clone;
type Scalar: Mul<Output = Self::Scalar> + Copy;
}

#[cgp_fn]
Expand Down
2 changes: 1 addition & 1 deletion crates/cgp-tests/tests/cgp_fn_tests/use_type_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait HasScalarType {
#[use_type(HasScalarType::{Scalar as S})]
pub fn rectangle_area(&self, #[implicit] width: S, #[implicit] height: S) -> S
where
S: Mul<Output = S> + Clone,
S: Mul<Output = S> + Copy,
{
let res: S = width * height;
res
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub trait CanCalculateArea {
#[use_type(HasScalarType::Scalar, HasErrorType::Error)]
impl AreaCalculator
where
Scalar: Mul<Output = Scalar> + Clone,
Scalar: Mul<Output = Scalar> + Copy,
{
fn area(&self, #[implicit] width: Scalar, #[implicit] height: Scalar) -> Result<Scalar, Error> {
Ok(width * height)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub trait CanCalculateArea {
#[uses(HasScalarType, HasErrorType)]
impl AreaCalculator
where
Self::Scalar: Mul<Output = Self::Scalar> + Clone,
Self::Scalar: Mul<Output = Self::Scalar> + Copy,
{
fn area(
&self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub trait CanCalculateArea<Types: HasScalarType> {
#[use_type(@Types::HasScalarType::Scalar, HasErrorType::Error)]
impl<Types> AreaCalculator<Types>
where
Scalar: Mul<Output = Scalar> + Clone,
Scalar: Mul<Output = Scalar> + Copy,
{
fn area(&self, #[implicit] width: Scalar, #[implicit] height: Scalar) -> Result<Scalar, Error> {
Ok(width * height)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ use core::ops::Mul;
use cgp::prelude::*;

#[cgp_component(AreaCalculator)]
pub trait CanCalculateArea {
fn area(&self) -> f64;
pub trait CanCalculateArea<Scalar> {
fn area(&self) -> Scalar;
}

#[cgp_impl(new RectangleArea)]
impl<Scalar> AreaCalculator
impl<Scalar> AreaCalculator<Scalar>
where
Scalar: Mul<Output = Scalar> + Clone + Into<f64>,
Scalar: Mul<Output = Scalar> + Copy,
{
fn area(&self, #[implicit] width: Scalar, #[implicit] height: Scalar) -> f64 {
(width * height).into()
fn area(&self, #[implicit] width: Scalar, #[implicit] height: Scalar) -> Scalar {
width * height
}
}

Expand All @@ -23,10 +23,15 @@ pub struct Rectangle {
pub height: f64,
}

delegate_and_check_components! {
CanUseRectangle for Rectangle;
delegate_components! {
Rectangle {
AreaCalculatorComponent:
RectangleArea,
}
}

check_components! {
CanUseRectangle for Rectangle {
AreaCalculatorComponent: f64,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use cgp::prelude::*;

#[cgp_type]
pub trait HasScalarType {
type Scalar: Clone;
type Scalar: Copy;
}

#[cgp_auto_getter]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use cgp::prelude::*;

#[cgp_type]
pub trait HasScalarType {
type Scalar: Clone;
type Scalar: Copy;
}

#[cgp_auto_getter]
Expand Down
20 changes: 8 additions & 12 deletions crates/cgp-tests/tests/getter_tests/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,23 @@ pub fn test_clone_getter() {
}

#[cgp_getter]
pub trait HasName: HasNameType<Name: Clone> {
pub trait HasName: HasNameType<Name: Copy> {
fn name(&self) -> Self::Name;
}

#[derive(HasField)]
pub struct App {
pub name: String,
pub name: &'static str,
}

delegate_components! {
App {
NameTypeProviderComponent: UseType<String>,
NameTypeProviderComponent: UseType<&'static str>,
NameGetterComponent: UseField<Symbol!("name")>,
}
}

let context = App {
name: "Alice".to_owned(),
};
let context = App { name: "Alice" };

assert_eq!(context.name(), "Alice");
}
Expand All @@ -39,24 +37,22 @@ pub fn test_clone_auto_getter() {
}

#[cgp_auto_getter]
pub trait HasName: HasNameType<Name: Clone> {
pub trait HasName: HasNameType<Name: Copy> {
fn name(&self) -> Self::Name;
}

#[derive(HasField)]
pub struct App {
pub name: String,
pub name: &'static str,
}

delegate_components! {
App {
NameTypeProviderComponent: UseType<String>,
NameTypeProviderComponent: UseType<&'static str>,
}
}

let context = App {
name: "Alice".to_owned(),
};
let context = App { name: "Alice" };

assert_eq!(context.name(), "Alice");
}
Loading