vweb: remove `return vweb.Result{}` everywhere

pull/7955/head
Alexander Medvednikov 2021-01-08 04:57:02 +01:00
parent e3f8d448c1
commit 352cf91ba2
4 changed files with 14 additions and 24 deletions

View File

@ -5,7 +5,8 @@
- Overloading of `>`, `<`, `!=`, and `==` operators. - Overloading of `>`, `<`, `!=`, and `==` operators.
- New struct updating syntax: `User{ ...u, name: 'new' }` to replace `{ u | name: 'new' }`. - New struct updating syntax: `User{ ...u, name: 'new' }` to replace `{ u | name: 'new' }`.
- `byte.str()` has been fixed and works like with all other numbers. `byte.ascii_str()` has been added. - `byte.str()` has been fixed and works like with all other numbers. `byte.ascii_str()` has been added.
- Smart cast in for-loops: `for mut x is string {}` - Smart cast in for loops: `for mut x is string {}`.
- `[noinit]` struct attribute to disallow direct struct initialization with `Foo{}`.
## V 0.2.1 ## V 0.2.1
*30 Dec 2020* *30 Dec 2020*

View File

@ -70,8 +70,7 @@ fn main() {
} }
pub fn (mut app App) index() vweb.Result { pub fn (mut app App) index() vweb.Result {
app.text('Hello, world from vweb!') return app.text('Hello world from vweb!')
return vweb.Result{}
} }
pub fn (app &App) init() { pub fn (app &App) init() {
@ -110,8 +109,7 @@ import vweb
import time import time
fn (mut app App) time() vweb.Result { fn (mut app App) time() vweb.Result {
app.text(time.now().format()) return app.text(time.now().format())
return vweb.Result{}
} }
``` ```
@ -352,8 +350,7 @@ pub fn (mut app App) new_article() vweb.Result {
title := app.form['title'] title := app.form['title']
text := app.form['text'] text := app.form['text']
if title == '' || text == '' { if title == '' || text == '' {
app.text('Empty text/title') return app.text('Empty text/title')
return vweb.Result{}
} }
article := Article{ article := Article{
title: title title: title
@ -363,8 +360,7 @@ pub fn (mut app App) new_article() vweb.Result {
sql app.db { sql app.db {
insert article into Article insert article into Article
} }
app.redirect('/') return app.redirect('/')
return vweb.Result{}
} }
``` ```
@ -391,8 +387,7 @@ import json
pub fn (mut app App) articles() vweb.Result { pub fn (mut app App) articles() vweb.Result {
articles := app.find_all_articles() articles := app.find_all_articles()
app.json(json.encode(articles)) return app.json(json.encode(articles))
return vweb.Result{}
} }
``` ```

View File

@ -5,29 +5,26 @@ struct App {
} }
pub fn (mut app App) no_attributes(a string) vweb.Result { pub fn (mut app App) no_attributes(a string) vweb.Result {
return vweb.Result{} return app.text('ok')
} }
// works fine, as long as fcn gets 1 arg and route takes 1 var // works fine, as long as fcn gets 1 arg and route takes 1 var
['/foo/:bar'] ['/foo/:bar']
pub fn (mut app App) foo(a string) vweb.Result { pub fn (mut app App) foo(a string) vweb.Result {
eprintln('foo') eprintln('foo')
app.html('works') return app.html('works')
return vweb.Result{}
} }
// segfault because path taks 0 vars and fcn takes 1 arg // segfault because path taks 0 vars and fcn takes 1 arg
['/bar'] ['/bar']
pub fn (mut app App) bar(a string) vweb.Result { pub fn (mut app App) bar(a string) vweb.Result {
app.html('works') return app.html('works')
return vweb.Result{}
} }
// no segfault, but it shouldnt compile // no segfault, but it shouldnt compile
['/cow/:low'] ['/cow/:low']
pub fn (mut app App) cow() vweb.Result { pub fn (mut app App) cow() vweb.Result {
app.html('works') return app.html('works')
return vweb.Result{}
} }
pub fn (app App) init_once() { pub fn (app App) init_once() {

View File

@ -53,8 +53,7 @@ pub fn (mut app App) simple() vweb.Result {
} }
pub fn (mut app App) html_page() vweb.Result { pub fn (mut app App) html_page() vweb.Result {
app.html('<h1>ok</h1>') return app.html('<h1>ok</h1>')
return vweb.Result{}
} }
// the following serve custom routes // the following serve custom routes
@ -63,8 +62,7 @@ pub fn (mut app App) settings(username string) vweb.Result {
if username !in known_users { if username !in known_users {
return app.not_found() return app.not_found()
} }
app.html('username: $username') return app.html('username: $username')
return vweb.Result{}
} }
['/:user/:repo/settings'] ['/:user/:repo/settings']
@ -72,8 +70,7 @@ pub fn (mut app App) user_repo_settings(username string, repository string) vweb
if username !in known_users { if username !in known_users {
return app.not_found() return app.not_found()
} }
app.html('username: $username | repository: $repository') return app.html('username: $username | repository: $repository')
return vweb.Result{}
} }
[post] [post]