Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to compile such an enum type #24

Open
oovm opened this issue Mar 26, 2021 · 0 comments
Open

Fail to compile such an enum type #24

oovm opened this issue Mar 26, 2021 · 0 comments

Comments

@oovm
Copy link

oovm commented Mar 26, 2021

I try to use this library, but I have a lot of things I don't understand.

for version 0.2.0-alpha.1

I want to implement the following types, are there any design problems?

type GcCollector = zerogc::dummy_impl::DummyCollectorId;
type GcValue<'gc> = Gc<'gc, Value<'gc>, GcCollector>;
type GcString<'gc> = Gc<'gc, String, GcCollector>;

#[derive(Debug, Clone, Trace)]
pub enum Value<'gc> {
    Null,
    Boolean(bool),
    String(GcString<'gc>),
    Array(Vec<GcValue<'gc>>),
    Object(HashMap<GcString<'gc>, GcValue<'gc>>),
}

How to deal with missing TraceImmutable?

error[E0277]: the trait bound `Gc<'gc, String, DummyCollectorId>: TraceImmutable` is not satisfied
  --> projects\nyar-interpreter\src\value\mod.rs:13:24
   |
13 | #[derive(Debug, Clone, Trace)]
   |                        ^^^^^ the trait `TraceImmutable` is not implemented for `Gc<'gc, String, DummyCollectorId>`
   |
   = note: required because of the requirements on the impl of `Trace` for `HashMap<Gc<'gc, String, DummyCollectorId>, Gc<'gc, value::Value<'gc>, DummyCollectorId>>`
   = note: required by `NEEDS_TRACE`
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

How to deal with missing GcRebrand

#[derive(Debug, Clone, Trace)]
pub enum Value<'gc> {
    Null,
    Boolean(bool),
    String(GcString<'gc>),
    Array(Vec<GcValue<'gc>>),
    Object(HashMap<String, GcValue<'gc>>),
}
error[E0277]: the trait bound `Gc<'gc, String, DummyCollectorId>: GcRebrand<'new_gc, Id>` is not satisfied
  --> projects\nyar-interpreter\src\value\mod.rs:17:12
   |
17 |     String(GcString<'gc>),
   |            ^^^^^^^^^^^^^ the trait `GcRebrand<'new_gc, Id>` is not implemented for `Gc<'gc, String, DummyCollectorId>`
   |
   = note: required by `assert_rebrand`
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
   |
14 | pub enum Value<'gc> where Gc<'gc, String, DummyCollectorId>: GcRebrand<'new_gc, Id> {
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

How to deal with missing types such as VecDeque, which trait bounds need to be implemented manually

#[derive(Debug, Clone, Trace)]
pub enum Value<'gc> {
    Null,
    Boolean(bool),
    String(GcString<'gc>),
    Array(VecDeque<GcValue<'gc>>),
    Object(HashMap<String, GcValue<'gc>>),
}
error[E0277]: the trait bound `VecDeque<Gc<'gc, value::Value<'gc>, DummyCollectorId>>: Trace` is not satisfied
  --> projects\nyar-interpreter\src\value\mod.rs:13:24
   |
13 | #[derive(Debug, Clone, Trace)]
   |                        ^^^^^ the trait `Trace` is not implemented for `VecDeque<Gc<'gc, value::Value<'gc>, DummyCollectorId>>`
   |
   = note: required by `NEEDS_TRACE`
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant