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

inline sub type start #1

Open
Licenser opened this issue Apr 18, 2020 · 0 comments
Open

inline sub type start #1

Licenser opened this issue Apr 18, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@Licenser
Copy link
Member

If we have a type that includes another datatype and so on, we still have a write command for each type even so at compile time we would know the entire 'chain'

an example would be:

struct S1 {
  v: Vec<u8>
}
struct S2 {
  s1: S1
}
struct S3 {
  s2: S2
}

serializing S3 would write {"s2": then {"s1": then {"v": then [ and only then the data.

A human observer will notice that we could reduce this to a single call of {"s2":{"s1":{"v":[.

At the same time we can notice that we do the same on the 'tail' where we will write ] then } then } then }.

A human observer, again, will notice that we could reduce this to a single call of ]}}}.

The same logic can be applied to combining <key>:{ and }, for keys that are neither first nor last to reduce write calls further.

An initial though is to split the encoding out into 3 sections:

  1. static start
  2. body
  3. static end

where 1 and 3 take the form of fn static_*() -> &'static u8 so the proc macro can call them on underlying structs to inline those parts of a sub type.

@Licenser Licenser added the enhancement New feature or request label Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant