Comments (13)
I have bad news, I'm surprised this didn't work.
---- src/room/create.rs - room::create::CreateEventContent::new (line 52) stdout ----
error[E0639]: cannot create non-exhaustive struct using struct expression
--> src/room/create.rs:59:14
|
10 | let create = CreateEventContent {
| ______________^
11 | | ..CreateEventContent::new(creator, true, version)
12 | | };
| |_^
Would a constructor for the required fields and "builder" methods for the optional fields be the next best thing?
from ruma.
Damn it, needs to be done using mutation then 🙄
from ruma.
The first commit to make some of our structs #[non_exhaustive]
is in master since yesterday: f9639e1.
from ruma.
Damn it, needs to be done using mutation then 🙄
Throwing random idea to (perceptively) reduce mutation:
What about declarative macro_rules only for Request object that expands to mutations? Will it be easier to consume?
let request = construct_request!(Request::default(), {
to: String::new("somestring"),
dir: Direction::Forward,
});
// which expands to
let request = {
let item = Request::new();
to: String::new("somestring");
dir: Direction::Forward;
item
};
Edit: remove "actually" because after re-reading it, I think I sounded annoying :D
from ruma.
@Kelerchian I thought I had mentioned that possibility here before, but apparently not! Maybe I did in the Matrix room, but whatever. The main reason I haven't done this yet is that there's no obvious syntax for such a macro. The one I came up previously was something like
let req = whatever!(Type::constructor(a, b) =>
.c = uint(1),
.d = "foo".into(),
);
but I like yours much more (you should fix the expanded form from let
to let mut
and :
to =
though 😛)! It should have a more general name than construct_request
, but I'd be happy to have this added to ruma-common
:)
Maybe we should also look into prior art, as I'm pretty sure other people have discussed this in the context of Rust, and IIRC I've heard of a language where this is a built-in feature.
from ruma.
The discussion about consuming non_exhaustive struct is here
Here's the related rfc page
The journey is still long it seems. And knowing there's no official way to do this in ruma crate, it might be just better to tell user to mutate and use helper if necessary.
I wrote a crate you can use here https://github.com/Kelerchian/assign
This is not published yet to crates.io because I don't want to publish anything not used by anyone,
notify me to publish this if you feel this is usable or copy paste / modify as you see fit and put in ruma-common.
Also I didn't follow your syntax recommendation because I'm not sure what =>
is supposed to mean in rust.
from ruma.
Also I didn't follow your syntax recommendation because I'm not sure what
=>
is supposed to mean in rust.
It was not a recommendation, as I said above I like your version much better.
I will think about naming a bit more (not a huge fan of assign!
right now) and decide how to proceed based on that.
Thanks a lot for helping with this! :)
from ruma.
You're welcome.
I was searching for an unused name in https://docs.rs/ and then assign
crossed my mind. JavaScript devs should be familiar with it.
from ruma.
Hm, that does make some sense. I will look into your new crate in more detail and probably send one or two PRs, but encourage you to release the first version now, to make sure you get the name on crates.io :)
Would you also be willing to give me / everyone with ownership of the ruma crates on crates.io (github:ruma:maintainers
) co-ownership of the crate?
from ruma.
I'm not comfortable with the crates.io owner system.
I'll add you as collaborator in the meantime.
The CI/CD is in place,
it'll build and test on pull requests
build, test, and publish on merge on master branch
from ruma.
I might be adding you guys as crate co-owners sometime soon
from ruma.
Hey @jplatte I know I have been advertising a tool for making a mutation looks like a declaration, but how about builder pattern?
Like this https://github.com/stiiifff/did-common-rust/blob/master/README.md
from ruma.
@Kelerchian That is what I was originally going for, however it means either writing or generating much much more code (which then results in longer compile times) and doesn't have any clear upsides for our use case.
from ruma.
Related Issues (20)
- Release automation does not pick up release notes if skipping all previous steps
- Add call.notify event (MSC4075)
- `m.direct` account data parsing should be more lenient HOT 2
- The `strike` and `font` HTML elements are deprecated and `s` is introduced HOT 1
- Implement Matrix 1.10 changes HOT 1
- Inconsistent m.call.candidates candidate definition
- Upgrade http to version 1.x HOT 6
- Upgrade html5ever HOT 1
- Make `room_alias_or_id::Variant` a public enum HOT 7
- How to send encrypted message to encrypted room HOT 3
- When user reply to their message, the reply mentions the current user HOT 1
- API responses always return a `200 OK` status code HOT 4
- Support optional path parameters for endpoints HOT 1
- Implement Matrix next version changes
- Make it harder to accidentally log sensitive data like user IDs HOT 4
- RoomMemberUnsigned is only useful in federation, but not used by servers HOT 5
- ruma rejects `Authorization: X-Matrix ...` headers that include optional whitespace around parameter pairs HOT 1
- `failures` is optional in responses to `/keys/signatures/upload` HOT 2
- Choose between `DeviceKeyId` and `DeviceSigningKeyId` HOT 1
- Handle encrypted stickers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ruma.