]> piware.de Git - learn-rust.git/log
learn-rust.git
21 months agoconcepts: rustfmt master
Martin Pitt [Fri, 6 Jan 2023 14:47:19 +0000 (15:47 +0100)]
concepts: rustfmt

22 months agoactix-server: Factorize App creation
Martin Pitt [Tue, 13 Dec 2022 13:29:05 +0000 (14:29 +0100)]
actix-server: Factorize App creation

This is too hard as a proper function, as App is too template-y. Use a
macro instead.

Thanks to Aravinth Manivannan for the suggestion!

22 months agoactix-server: Add "reverse input" websocket route
Martin Pitt [Mon, 12 Dec 2022 07:35:58 +0000 (08:35 +0100)]
actix-server: Add "reverse input" websocket route

22 months agoactix-server: Add echo websocket route
Martin Pitt [Sat, 10 Dec 2022 11:50:51 +0000 (12:50 +0100)]
actix-server: Add echo websocket route

22 months agoactix-server: Make hello route work with HEAD
Martin Pitt [Sat, 10 Dec 2022 11:34:07 +0000 (12:34 +0100)]
actix-server: Make hello route work with HEAD

This is a little bit tricky:
https://github.com/actix/actix-web/issues/2702

22 months agoactix-server: Add static file route with gz support
Martin Pitt [Sat, 10 Dec 2022 10:59:12 +0000 (11:59 +0100)]
actix-server: Add static file route with gz support

This shows how to serve dynamically computed file paths/types, with gzip
transport encoding support.

22 months agoactix-server: Add static directory route
Martin Pitt [Fri, 9 Dec 2022 20:58:53 +0000 (21:58 +0100)]
actix-server: Add static directory route

22 months agoactix-server: Initial version with /hello/name route
Martin Pitt [Fri, 9 Dec 2022 15:15:21 +0000 (16:15 +0100)]
actix-server: Initial version with /hello/name route

See https://actix.rs/

22 months agoaxum-server: Add unit tests for static directory route
Martin Pitt [Fri, 9 Dec 2022 13:12:38 +0000 (14:12 +0100)]
axum-server: Add unit tests for static directory route

22 months agoaxum-server: Add unit test for /hello route
Martin Pitt [Fri, 9 Dec 2022 12:33:45 +0000 (13:33 +0100)]
axum-server: Add unit test for /hello route

Similar to what commit be3212fb7c5a did for warp-server. Split out the
whole app router into a separate app() function, to make it accessible
to unit testing.

22 months agoaxum-server: Sync directory route and port with warp-server
Martin Pitt [Fri, 9 Dec 2022 11:05:11 +0000 (12:05 +0100)]
axum-server: Sync directory route and port with warp-server

22 months agowarp-server: Add route for serving static directory
Martin Pitt [Fri, 9 Dec 2022 09:25:18 +0000 (10:25 +0100)]
warp-server: Add route for serving static directory

Add a static/ file tree for testing.

22 months agowarp-server: Add unit tests for websocket routes
Martin Pitt [Fri, 9 Dec 2022 08:59:39 +0000 (09:59 +0100)]
warp-server: Add unit tests for websocket routes

22 months agowarp-server: Add unit test for /hello route
Martin Pitt [Fri, 9 Dec 2022 08:00:12 +0000 (09:00 +0100)]
warp-server: Add unit test for /hello route

Split out the API into a separate function, to make it accessible for
unit tests.

22 months agoRevert "warp-server: Move handlers and filters into submodules"
Martin Pitt [Fri, 9 Dec 2022 08:02:25 +0000 (09:02 +0100)]
Revert "warp-server: Move handlers and filters into submodules"

We don't need this after all, exposing the API filter is enough.

This reverts commit 6d7b20b8f00be8b9cc86ad835d64bceca8a8b628.

22 months agowarp-server: Move handlers and filters into submodules
Martin Pitt [Fri, 9 Dec 2022 07:47:09 +0000 (08:47 +0100)]
warp-server: Move handlers and filters into submodules

Exposing the filters as functions makes them accessible to unit testing.

23 months agoaxum-server: Serve whole directory
Martin Pitt [Sat, 12 Nov 2022 10:18:04 +0000 (11:18 +0100)]
axum-server: Serve whole directory

23 months agoaxum-server: Add websocket route
Martin Pitt [Sat, 12 Nov 2022 09:54:47 +0000 (10:54 +0100)]
axum-server: Add websocket route

23 months agoaxum-server: Show User-Agent:
Martin Pitt [Sat, 12 Nov 2022 09:24:01 +0000 (10:24 +0100)]
axum-server: Show User-Agent:

23 months agoaxum-server: Serve single static file
Martin Pitt [Sat, 12 Nov 2022 07:35:28 +0000 (08:35 +0100)]
axum-server: Serve single static file

23 months agoaxum-server: Initial hello world
Martin Pitt [Sat, 12 Nov 2022 06:35:33 +0000 (07:35 +0100)]
axum-server: Initial hello world

23 months agowarp-server: Add route for reversing websocket messages
Martin Pitt [Wed, 9 Nov 2022 22:23:58 +0000 (23:23 +0100)]
warp-server: Add route for reversing websocket messages

23 months agowarp-server: Move handlers into proper functions
Martin Pitt [Sun, 6 Nov 2022 10:53:58 +0000 (11:53 +0100)]
warp-server: Move handlers into proper functions

This is easier to follow, and makes it more obvious what the types are.

2 years agowarp-server: Proper websocket error reporting
Martin Pitt [Tue, 1 Nov 2022 18:22:43 +0000 (19:22 +0100)]
warp-server: Proper websocket error reporting

2 years agowarp-server: Add logging
Martin Pitt [Tue, 1 Nov 2022 18:03:58 +0000 (19:03 +0100)]
warp-server: Add logging

2 years agowarp-server: Add echo websocket route
Martin Pitt [Tue, 1 Nov 2022 16:46:30 +0000 (17:46 +0100)]
warp-server: Add echo websocket route

2 years agowarp-server: Add User-Agent header filter
Martin Pitt [Tue, 1 Nov 2022 15:30:53 +0000 (16:30 +0100)]
warp-server: Add User-Agent header filter

2 years agowarp-server: Initial hello world
Martin Pitt [Tue, 1 Nov 2022 15:15:39 +0000 (16:15 +0100)]
warp-server: Initial hello world

2 years agogtk4-hello-world: Drop unnecessary move
Martin Pitt [Tue, 4 Oct 2022 07:27:06 +0000 (09:27 +0200)]
gtk4-hello-world: Drop unnecessary move

2 years agohyper-server: Initial version
Martin Pitt [Sun, 18 Sep 2022 18:28:53 +0000 (20:28 +0200)]
hyper-server: Initial version

2 years agotokio-tutorial-mini-redis: Add proper error handling
Martin Pitt [Sun, 18 Sep 2022 18:04:38 +0000 (20:04 +0200)]
tokio-tutorial-mini-redis: Add proper error handling

Keep unwrapping accept() and Mutex failures, these are early/unlikely enough
to be okay to crash.

2 years agotokio-tutorial-mini-redis: Add logging
Martin Pitt [Sun, 18 Sep 2022 17:46:12 +0000 (19:46 +0200)]
tokio-tutorial-mini-redis: Add logging

2 years agotokio-tutorial-mini-redis: Show return value in client
Martin Pitt [Fri, 16 Sep 2022 12:42:09 +0000 (14:42 +0200)]
tokio-tutorial-mini-redis: Show return value in client

Use an oneshot message sender to deliver the result.

2 years agotokio-tutorial-mini-redis: Add first client version
Martin Pitt [Fri, 16 Sep 2022 12:27:33 +0000 (14:27 +0200)]
tokio-tutorial-mini-redis: Add first client version

Uses message passing instead of mutexes. Does not yet send back values
from the manager.

2 years agotokio-tutorial-mini-redis: Rename to server binary
Martin Pitt [Fri, 16 Sep 2022 12:11:19 +0000 (14:11 +0200)]
tokio-tutorial-mini-redis: Rename to server binary

Invoke with

    cargo run --bin server

2 years agotokio-tutorial-mini-redis: Shared global state
Martin Pitt [Fri, 16 Sep 2022 12:02:30 +0000 (14:02 +0200)]
tokio-tutorial-mini-redis: Shared global state

2 years agotokio-tutorial-mini-redis: Initial protocol
Martin Pitt [Fri, 16 Sep 2022 11:49:23 +0000 (13:49 +0200)]
tokio-tutorial-mini-redis: Initial protocol

Implement GET/SET, without shared state yet.

Move the original API demo as an example. Run it with

    cargo run --example hello-redis

2 years agotokio-tutorial-mini-redis: Initial demo
Martin Pitt [Fri, 16 Sep 2022 09:56:13 +0000 (11:56 +0200)]
tokio-tutorial-mini-redis: Initial demo

https://tokio.rs/tokio/tutorial/

2 years agotokio-tutorial-jbarszczewski: Implement actual balance data handling
Martin Pitt [Fri, 16 Sep 2022 09:41:27 +0000 (11:41 +0200)]
tokio-tutorial-jbarszczewski: Implement actual balance data handling

2 years agotokio-tutorial-jbarszczewski: Add GET/POST parsing
Martin Pitt [Fri, 16 Sep 2022 09:17:26 +0000 (11:17 +0200)]
tokio-tutorial-jbarszczewski: Add GET/POST parsing

2 years agotokio-tutorial-jbarszczewski: Handle each connection in separate task
Martin Pitt [Fri, 16 Sep 2022 08:56:43 +0000 (10:56 +0200)]
tokio-tutorial-jbarszczewski: Handle each connection in separate task

2 years agotokio-tutorial-jbarszczewski: Initial savings balance API
Martin Pitt [Fri, 16 Sep 2022 08:53:18 +0000 (10:53 +0200)]
tokio-tutorial-jbarszczewski: Initial savings balance API

2 years agotokio-tutorial-jbarszczewski: Hello world
Martin Pitt [Fri, 16 Sep 2022 08:44:21 +0000 (10:44 +0200)]
tokio-tutorial-jbarszczewski: Hello world

Demonstrating async fn and inline async block

https://jbarszczewski.com/basics-of-asynchronous-rust-with-tokio

2 years agoasync-http: Unit test for handle_connection()
Martin Pitt [Fri, 16 Sep 2022 07:39:05 +0000 (09:39 +0200)]
async-http: Unit test for handle_connection()

2 years agoasync-http: Serve requests in parallel in threads
Martin Pitt [Fri, 16 Sep 2022 07:03:46 +0000 (09:03 +0200)]
async-http: Serve requests in parallel in threads

Use async_std::task::spawn to launch a request in a thread.

Now even synchronous sleep does not block other requests, as long as
they don't exceed the thread pool capacity.

2 years agoasync-http: Serve requests concurrently
Martin Pitt [Fri, 16 Sep 2022 06:47:48 +0000 (08:47 +0200)]
async-http: Serve requests concurrently

Move to asyncstd TCPListener and futures Stream, so that the incoming
loop does not serialize/block requests any more.

This is still single-threaded. That can be demonstrated with replacing
the async sleep with a sync one (commented out). Then /sleep will block
other requests again.

2 years agoasync-http: Move to async main and handler function
Martin Pitt [Fri, 16 Sep 2022 06:19:15 +0000 (08:19 +0200)]
async-http: Move to async main and handler function

This does not yet handle requests concurrently. Demonstrate with adding
a /sleep path.

2 years agoasync-http: Fix unhandled warning
Martin Pitt [Fri, 16 Sep 2022 06:13:04 +0000 (08:13 +0200)]
async-http: Fix unhandled warning

2 years agoasync-http: Add logging
Martin Pitt [Fri, 16 Sep 2022 06:12:14 +0000 (08:12 +0200)]
async-http: Add logging

2 years agoasync-http: Initial sync version
Martin Pitt [Fri, 16 Sep 2022 06:04:56 +0000 (08:04 +0200)]
async-http: Initial sync version

2 years agoAdd GTK 3 hello world
Martin Pitt [Mon, 18 Apr 2022 18:34:34 +0000 (20:34 +0200)]
Add GTK 3 hello world

2 years agoAdd GTK 4 hello world
Martin Pitt [Mon, 18 Apr 2022 09:44:02 +0000 (11:44 +0200)]
Add GTK 4 hello world

https://gtk-rs.org/gtk4-rs/stable/latest/book/introduction.html

3 years agoserde: Show ≥ info logs by default
Martin Pitt [Sun, 26 Sep 2021 08:47:26 +0000 (10:47 +0200)]
serde: Show ≥ info logs by default

3 years agoserde: Use log framework
Martin Pitt [Sat, 25 Sep 2021 10:42:02 +0000 (12:42 +0200)]
serde: Use log framework

Run with `RUST_LOG=debug` to see the serialized message.

3 years agoserde: Read back from file and deserialize
Martin Pitt [Sat, 25 Sep 2021 10:22:27 +0000 (12:22 +0200)]
serde: Read back from file and deserialize

3 years agoserde: Use error propagation
Martin Pitt [Sat, 25 Sep 2021 10:12:45 +0000 (12:12 +0200)]
serde: Use error propagation

3 years agoserde: Write JSON to file
Martin Pitt [Sat, 25 Sep 2021 08:20:01 +0000 (10:20 +0200)]
serde: Write JSON to file

3 years agoserde: Data types and initial serialization
Martin Pitt [Sat, 25 Sep 2021 06:59:37 +0000 (08:59 +0200)]
serde: Data types and initial serialization

3 years agosimple-http: Implement ThreadPool cleanup
Martin Pitt [Sun, 19 Sep 2021 09:48:51 +0000 (11:48 +0200)]
simple-http: Implement ThreadPool cleanup

Introduce Terminate message. Test this by only accepting two requests
and then letting `pool` go out of scope.

3 years agosimple-http: Implement ThreadPool messaging
Martin Pitt [Sun, 19 Sep 2021 09:37:29 +0000 (11:37 +0200)]
simple-http: Implement ThreadPool messaging

3 years agosimple-http: Add scaffolding for thread pool implementation
Martin Pitt [Sun, 19 Sep 2021 08:38:31 +0000 (10:38 +0200)]
simple-http: Add scaffolding for thread pool implementation

Turn into library crate. Add ThreadPool stub to src/lib.

3 years agosimple-http: Naïve unlimited threads
Martin Pitt [Sat, 11 Sep 2021 09:36:22 +0000 (11:36 +0200)]
simple-http: Naïve unlimited threads

This introduces a DoS with too many parallel requests.

3 years agosimple-http: Introduce a slow path
Martin Pitt [Sun, 5 Sep 2021 06:09:28 +0000 (08:09 +0200)]
simple-http: Introduce a slow path

3 years agosimple-http: Parse path from request
Martin Pitt [Fri, 3 Sep 2021 08:06:07 +0000 (10:06 +0200)]
simple-http: Parse path from request

3 years agosimple-http: Check hardcoded root path, add 404 page
Martin Pitt [Wed, 1 Sep 2021 10:17:54 +0000 (12:17 +0200)]
simple-http: Check hardcoded root path, add 404 page

3 years agosimple-http: Initial skeleton
Martin Pitt [Mon, 30 Aug 2021 17:39:44 +0000 (19:39 +0200)]
simple-http: Initial skeleton

3 years agoconcepts: Add alternative Post implementation with states as types
Martin Pitt [Sun, 29 Aug 2021 14:45:02 +0000 (16:45 +0200)]
concepts: Add alternative Post implementation with states as types

3 years agoconcepts: require two Post approvals
Martin Pitt [Sun, 29 Aug 2021 14:25:47 +0000 (16:25 +0200)]
concepts: require two Post approvals

3 years agoconcepts: Add Post.reject() transition
Martin Pitt [Sun, 29 Aug 2021 14:21:01 +0000 (16:21 +0200)]
concepts: Add Post.reject() transition

3 years agoconcepts: Rewrite Post without Option
Martin Pitt [Sun, 29 Aug 2021 14:12:41 +0000 (16:12 +0200)]
concepts: Rewrite Post without Option

This gets rid of a lot of extra Option handling code, at the price of
having to rebuild instead of pass through non-changing states.

3 years agoconcepts: Dynamic trait objects
Martin Pitt [Sun, 29 Aug 2021 13:55:13 +0000 (15:55 +0200)]
concepts: Dynamic trait objects

3 years agoconcepts: Shared memory and mutex between threads
Martin Pitt [Sun, 29 Aug 2021 08:15:43 +0000 (10:15 +0200)]
concepts: Shared memory and mutex between threads

3 years agoconcepts: Threads and message passing
Martin Pitt [Sun, 29 Aug 2021 07:21:30 +0000 (09:21 +0200)]
concepts: Threads and message passing

3 years agoconcepts: Rewrite Cacher tests using RefCell
Martin Pitt [Sun, 29 Aug 2021 06:49:44 +0000 (08:49 +0200)]
concepts: Rewrite Cacher tests using RefCell

Avoids an external crate.

3 years agoMove top-level files into concepts/
Martin Pitt [Sun, 29 Aug 2021 05:54:59 +0000 (07:54 +0200)]
Move top-level files into concepts/

As this now contains multiple projects, it was too messy.

3 years agoCall Rust function from C: Complex cases
Martin Pitt [Fri, 27 Aug 2021 12:49:22 +0000 (14:49 +0200)]
Call Rust function from C: Complex cases

Add three functions which take/return strings and string arrays. This
creates some interesting problems how to combine the C semantics of
returning a char** with the Rust semantics of freeing objects once they
go out of scope.

This now also relies on the Rust standard library, which needs a few
system libraries. Link them.

3 years agoCall Rust function from C: Skeleton
Martin Pitt [Fri, 27 Aug 2021 09:08:54 +0000 (11:08 +0200)]
Call Rust function from C: Skeleton

3 years agoImplement the rest of c-mounts.c in Rust
Martin Pitt [Fri, 27 Aug 2021 07:27:37 +0000 (09:27 +0200)]
Implement the rest of c-mounts.c in Rust

Use errno crate for human-readable error formatting.

3 years agoInitial libmount function call from Rust
Martin Pitt [Fri, 27 Aug 2021 06:43:12 +0000 (08:43 +0200)]
Initial libmount function call from Rust

Follow "A little C with your Rust" [1].

Set up cargo and main.rs skeleton and call one of the simplest possible
functions from libmount: mnt_get_fstab_path().

Use bindgen [1] to translate libmount's header file into a Rust
interface. This requires a few hacks:

 - bindgen does not accept the original header right away, as it can't
   find stdarg.h. Avoid this by dropping the (unnecessary) stdio.h
   include.
 - bindgen does not know about `size_t`. Hack around that with a typedef
   for now.
 - Suppress warnings about constant/identifier naming.

[1] https://rust-lang.github.io/rust-bindgen/command-line-usage.html
[2] https://docs.rust-embedded.org/book/interoperability/c-with-rust.html

3 years agoC from Rust: Reference C programs
Martin Pitt [Fri, 27 Aug 2021 05:09:50 +0000 (07:09 +0200)]
C from Rust: Reference C programs

3 years agoAdd .gitignore
Martin Pitt [Fri, 27 Aug 2021 04:56:44 +0000 (06:56 +0200)]
Add .gitignore

3 years agoIterators
Martin Pitt [Thu, 26 Aug 2021 16:30:39 +0000 (18:30 +0200)]
Iterators

3 years agoConsistently use into_iter() with collect()
Martin Pitt [Thu, 26 Aug 2021 15:23:55 +0000 (17:23 +0200)]
Consistently use into_iter() with collect()

3 years agoReplace unsafe test code with global_counter
Martin Pitt [Wed, 25 Aug 2021 06:36:47 +0000 (08:36 +0200)]
Replace unsafe test code with global_counter

https://docs.rs/crate/global_counter

3 years agoClosures and Cacher object
Martin Pitt [Wed, 25 Aug 2021 06:25:30 +0000 (08:25 +0200)]
Closures and Cacher object

3 years agoAdd integration test
Martin Pitt [Tue, 24 Aug 2021 07:56:13 +0000 (09:56 +0200)]
Add integration test

3 years agoMove helper functions into src/lib.rs
Martin Pitt [Tue, 24 Aug 2021 07:51:38 +0000 (09:51 +0200)]
Move helper functions into src/lib.rs

This enables writing integration tests. Pure binary crates can't have
them:

https://doc.rust-lang.org/stable/book/ch11-03-test-organization.html#integration-tests-for-binary-crates

3 years agoGenerics and Traits
Martin Pitt [Tue, 24 Aug 2021 05:21:03 +0000 (07:21 +0200)]
Generics and Traits

3 years agoReturn style fix
Martin Pitt [Tue, 24 Aug 2021 04:53:24 +0000 (06:53 +0200)]
Return style fix

3 years agoFile reading with standard fs API
Martin Pitt [Mon, 23 Aug 2021 12:07:13 +0000 (14:07 +0200)]
File reading with standard fs API

3 years agoFile reading and error handling using ?
Martin Pitt [Mon, 23 Aug 2021 12:02:33 +0000 (14:02 +0200)]
File reading and error handling using ?

3 years agoFile reading and simple error handling
Martin Pitt [Mon, 23 Aug 2021 11:52:54 +0000 (13:52 +0200)]
File reading and simple error handling

3 years agoSplit into functions
Martin Pitt [Mon, 23 Aug 2021 11:18:15 +0000 (13:18 +0200)]
Split into functions

3 years agoHashMap
Martin Pitt [Mon, 23 Aug 2021 10:03:33 +0000 (12:03 +0200)]
HashMap

3 years agotest word_utils
Martin Pitt [Sun, 22 Aug 2021 14:17:51 +0000 (16:17 +0200)]
test word_utils

3 years agoVector iteration
Martin Pitt [Sun, 22 Aug 2021 14:03:34 +0000 (16:03 +0200)]
Vector iteration

3 years agoMove word_utils to separate file
Martin Pitt [Sun, 22 Aug 2021 13:31:47 +0000 (15:31 +0200)]
Move word_utils to separate file

3 years agoPut functions into module
Martin Pitt [Sun, 22 Aug 2021 13:24:27 +0000 (15:24 +0200)]
Put functions into module

3 years agoReferences, slices, Option
Martin Pitt [Sun, 22 Aug 2021 13:21:27 +0000 (15:21 +0200)]
References, slices, Option