-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Feature/Enhancement RequestThis issue is made to request a feature or an enhancement to an existing one.This issue is made to request a feature or an enhancement to an existing one.Type: SpecificationEverything related to the formal specification of how V should behaveEverything related to the formal specification of how V should behave
Description
This would be super useful for our vweb
framework which has some attributes. Using this technique we could remove compiler magic for the vweb
module and make a more generic solution.
Requirements
- It should be able to define methods on it. Those methods can be looked up at compile time then and be called.
- It should be able to contain fields/parameters.
- It should not be able to pass an attribute as a type parameter in function arguments nor cast or instanitate something.
- It should not have any field visibility like
pub
ormut
A: struct attribute - attribute
an attribute struct shouldn't have struct embedding,
pub mut
, be initialized nor be used as a type parameter.
An example would look like:
enum HttpMethod { get post put delete patch }
[attribute]
struct Route {
path string
method HttpMethod
}
// .get looks a little bit weird. we could use also a string with `'GET'` or something. but it's only an example here.
[Route{'/index', .get}] // or even [Route{path: '/index', method: .get}]
fn index() {}
B: attribute keyword
This would introduce another keyword but would be good as well is:
enum HttpMethod { get post put delete patch }
attribute Route(path string, method HttpMethod)
// .get looks a little bit weird. we could use also a string with `'GET'` or something. but it's only an example here.
[Route('/index', .get)] // or even [Route(path: '/index', method: .get)]
fn index() {}
Obviously, the last propsal would introduce more complexity to the compiler which could also slow it down. But the syntax will be shorter and structs wouldn't be used for different things.
Using attributes
Either attribute using is always like this: [Route('/index', .get)]
.
Or if we decide to use a castraed form of a struct, we could use the syntax [Route{'/index', .get}]
Terisback, ArnCarveris, IngwiePhoenix, Delta456, danieldaeschle and 8 moredumblob
Metadata
Metadata
Assignees
Labels
Feature/Enhancement RequestThis issue is made to request a feature or an enhancement to an existing one.This issue is made to request a feature or an enhancement to an existing one.Type: SpecificationEverything related to the formal specification of how V should behaveEverything related to the formal specification of how V should behave