#dang constructors
1 messages · Page 1 of 1 (latest)
for this, yeah honestly I'll probably need to add support for explicit constructors.
the closest thing you can do is this:
```graphql
type MyType {
let privateArg: String!
}
because `privateArg` is `String!`, Dang will make it a required constructor arg (otherwise you'd have a `null` non-null!), and because it's `let` it won't be a public field
but, if you do `let: privateArg: String! = "default"` it won't be an arg because it has a value present
In this particular case:
type Rust {
"""Source directory."""
pub source: Directory! @defaultPath(path:"/")
"""Version (image tag) to use from the official image repository as a base container."""
pub version: String! = "latest"
"""Container to use as a base container."""
pub base: Container! = container().from("rust:" + version)
}
I want to be able to set a container, OR set a version and use the default container.
I'm able to do that with other SDKs and constructors.
Frankly, I'm not sure what's the best solution.
It might be a good temporary one to introduce the same @private annotation as in the Go SDK. That doesn't require a language change, like constructors would.
Would this help?
We'll need constructors for our immediate plans anyway, since they involve a special type that can't be saved as a field (Workspace). And currently constructor args are derived from fields
looks great!
dang constructors
@last imp for https://github.com/vito/dang/issues/24 - what if I just made constructors behave like functions with a hardcoded expected return value? so your example would work, and in other cases you just add an explicit self return (which should be already somewhat familiar from other chaining methods)
going with that for now, feels most natural
Works for me
@last imp fixed all 3 issues, thanks again for the reports! 🙏
@last imp just fyi, i pushed a change to switch dang fmt from tabs to two spaces, pinging in case you were about to commit a big reformat, to avoid another one 😛
actually, I prefer following language opinionated style. That way I don't have to waste brainpower on deciding what to do, because it's already decided for me. 😄
Is there maybe a toolchain module I can install to make formatting easier?
the LSP integration supports it, so for me it just formats on save now. the Zed extension has been published too
to do a one-off, dang fmt -wl **/*.dang
no toolchain at the moment - probably a good idea now that generators have shipped
I wonder: with the latest changes, would something like this work?
new(
"""Source directory"""
source: Directory! @defaultPath(path:"/")
"""Version (image tag) to use from the official image repository as a base container"""
version: String! = "latest"
"""Container to use as a base container"""
container: Container! = Dagger.container().from("rust:" + version)
) {
it would make an elegant way to set default values, but it's not that much better than
self.container = container ?? Dagger.container().from("rust:" + (version ?? "latest"))
(BTW I think I'll just use Dagger. and not import Dagger unless I have to. I like the explicit nature of it)
doesn't work at the moment, might be difficult. the version passed to from resolves to the engine version
yeah, that's what I thought. doesn't really change anything from a user perspective, so it's not the end of the world.
update: it wasn't difficult
pushed - this works now!