aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/modules/bot.sloth7
-rw-r--r--examples/modules/mod.sloth15
-rw-r--r--examples/webserver.sloth108
3 files changed, 130 insertions, 0 deletions
diff --git a/examples/modules/bot.sloth b/examples/modules/bot.sloth
new file mode 100644
index 0000000..1355ddb
--- /dev/null
+++ b/examples/modules/bot.sloth
@@ -0,0 +1,7 @@
+use slowcord::DiscordBot;
+
+pub type Bot;
+
+impl DiscordBot for Bot {
+ # TODO:
+}
diff --git a/examples/modules/mod.sloth b/examples/modules/mod.sloth
new file mode 100644
index 0000000..75be7e1
--- /dev/null
+++ b/examples/modules/mod.sloth
@@ -0,0 +1,15 @@
+# Root module - Run this to start program
+
+pub use extern "logging";
+pub use extern "dotenv";
+pub use extern "slowcord";
+pub use extern "sqlite";
+
+use logging::LogLevel;
+use bot::Bot;
+
+logging::set_loglevel(LogLevel::WARN);
+
+val token = dotenv::get("TOKEN");
+val bot = Bot::new();
+bot.start(token);
diff --git a/examples/webserver.sloth b/examples/webserver.sloth
new file mode 100644
index 0000000..abbead3
--- /dev/null
+++ b/examples/webserver.sloth
@@ -0,0 +1,108 @@
+# Include the external dependency itself as a module named "slow_api"
+use extern "slowapi" as slow_api;
+
+# Use some things from the "slow_api" module
+use std::serde::Serializable;
+use std::serde::format::Json;
+
+use slow_api::{SlowAPI, Method};
+
+# Construct a slow API server
+val server = SlowApi();
+
+type Person derives Serializable = {
+ name: String,
+ age: Option<String>
+};
+
+fn hello_route(
+ name: Argument<String>,
+ age: Argument<Option<String>>,
+) -> Json<Person> {
+ Person { name, age }
+}
+
+# Start the server
+server
+ .route(Method::GET, "/hello", hello_route)
+ .start("0.0.0.0:8000");
+#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+###
+type Poggies;
+
+trait Constructor<..T> {
+ fn new(..T) -> Self;
+}
+
+impl Constructor<> for Poggies {
+ fn new() -> Self {
+ #
+ }
+}
+
+impl<T: Constructor<>> Default for T {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+###
+type Person = {
+ name: String,
+ age: i32,
+};
+
+type Person derives Serialize, Deserialize = {
+ name: String,
+ age: i32,
+};
+
+@route::get("/teacup") # vvvvvv - Requires T to implement Serialize
+fn teacup_route() -> Response<Person> {
+ Response(418, Person {
+ name: "Cody Q",
+ age: 17,
+ })
+}