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

For the type pub struct A(pub B) in Dart, use either B or class A { final B value; }. #1936

Closed
iota9star opened this issue May 13, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@iota9star
Copy link

Is your feature request related to a problem? Please describe.
Just like the title says.
image

@iota9star iota9star added the enhancement New feature or request label May 13, 2024
@fzyzcjy
Copy link
Owner

fzyzcjy commented May 14, 2024

Looks reasonable! (I prefer the latter, since that's partially why people need newtype pattern). Feel free to PR, alternatively I will work on it in the next batch.

@Zacchaeus-Oluwole
Copy link

Zacchaeus-Oluwole commented May 14, 2024

Is your feature request related to a problem? Please describe. Just like the title says. image

I have a similar issue:

@sealed
class FrSerialport extends RustOpaque {
  FrSerialport.dcoDecode(List<dynamic> wire)
      : super.dcoDecode(wire, _kStaticData);

  FrSerialport.sseDecode(int ptr, int externalSizeOnNative)
      : super.sseDecode(ptr, externalSizeOnNative, _kStaticData);

  static final _kStaticData = RustArcStaticData(
    rustArcIncrementStrongCount:
        RustLib.instance.api.rust_arc_increment_strong_count_FrSerialport,
    rustArcDecrementStrongCount:
        RustLib.instance.api.rust_arc_decrement_strong_count_FrSerialport,
    rustArcDecrementStrongCountPtr:
        RustLib.instance.api.rust_arc_decrement_strong_count_FrSerialportPtr,
  );

  static Future<FrSerialport> connect(
          {required String portName, dynamic hint}) =>
      RustLib.instance.api.frSerialportConnect(portName: portName, hint: hint);
      
  static Future<List<String>> getPorts({dynamic hint}) =>
      RustLib.instance.api.frSerialportGetPorts(hint: hint);

  Future<String> get({dynamic hint}) => RustLib.instance.api.frSerialportGet(
        that: this,
      );
  Future<void> send({required String data, dynamic hint}) =>
      RustLib.instance.api.frSerialportSend(
        that: this,
        data: data,
      );
}

In the above code, i can only access FrSerialport.connect and FrSerialport.getPorts but i can't access FrSerialport.get and FrSerialport.send.
I noticed it's all the methods that take in self as an argument are the ones i can't access.

Please, what is the way out of this issue. is there a solution to it already?

@fzyzcjy
Copy link
Owner

fzyzcjy commented May 14, 2024

In the above code, i can only access FrSerialport.connect and FrSerialport.getPorts but i can't access FrSerialport.get and FrSerialport.send.
I noticed it's all the methods that take in self as an argument are the ones i can't access.

@Zacchaeus-Oluwole Hi, could you please create a separate issue and provide a minimal reproducible sample? Without the corresponding Rust code it is not easy to say what is going on :/

@Zacchaeus-Oluwole
Copy link

Alright,I will do that. Thank you

@fzyzcjy
Copy link
Owner

fzyzcjy commented May 15, 2024

You are welcome

@fzyzcjy
Copy link
Owner

fzyzcjy commented May 19, 2024

It seems that this is already supported. For example, in the tests:

image

image

Thus, I guess your question is "why it is opaque instead of non-opaque". Thus try to put #[frb(non_opaque)] on it.

Feel free to open if this does not solve your question!

@fzyzcjy fzyzcjy closed this as completed May 19, 2024
Copy link
Contributor

github-actions bot commented Jun 2, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants