Browse Source

Initial commit

Includes some unimportant files
master
Bradlee Speice 4 years ago
parent
commit
474995194b
7 changed files with 130 additions and 0 deletions
  1. BIN
      .Cargo.toml.swp
  2. +3
    -0
      .gitignore
  3. +11
    -0
      Cargo.toml
  4. +20
    -0
      src/bassdrive.rs
  5. +18
    -0
      src/broadcast.rs
  6. +31
    -0
      src/main.rs
  7. +47
    -0
      src/main_hyper.rs.bak

BIN
.Cargo.toml.swp View File


+ 3
- 0
.gitignore View File

@@ -0,0 +1,3 @@
target
Cargo.lock
target

+ 11
- 0
Cargo.toml View File

@@ -0,0 +1,11 @@
[package]
name = "nutone"
version = "0.1.0"
authors = ["Bradlee Speice <bradlee.speice@gmail.com>"]

[dependencies]
html5ever = "*"
rss = "*"
hyper = "*"
iron = "*"
router = "*"

+ 20
- 0
src/bassdrive.rs View File

@@ -0,0 +1,20 @@
extern crate hyper;
extern crate rss;

use rss::Channel;
use std::str::FromStr;

use broadcast::Broadcaster;

pub struct BassDrive {
pub url: String
}

impl BassDrive {
}

impl Broadcaster for BassDrive {
fn broadcast(&self) -> Channel {
Channel::from_str("").unwrap()
}
}

+ 18
- 0
src/broadcast.rs View File

@@ -0,0 +1,18 @@
extern crate rss;
extern crate hyper;

use hyper::server::{Request, Response};
use rss::Channel;

pub trait Broadcaster {
fn broadcast(&self) -> Channel;
}

#[allow(unused)]
pub fn build_broadcast<T: Broadcaster>(b: T) -> Box<Fn(Request, Response)> {
let channel = b.broadcast();

Box::new(move |_: Request, res: Response| {
res.send(channel.to_string().as_bytes());
})
}

+ 31
- 0
src/main.rs View File

@@ -0,0 +1,31 @@
extern crate iron;
extern crate router;

use iron::Handler;
use iron::status;
use iron::IronResult;
use iron::Response;
use iron::Request;
use iron::Iron;
use router::Router;

struct EchoHandler {
message: String
}

impl Handler for EchoHandler {
fn handle(&self, _: &mut Request) -> IronResult<Response> {
Ok(Response::with((status::Ok, self.message.clone())))
}
}

fn main() {
let echo = EchoHandler {
message: "FINALLY ARE YOU FREAKING KIDDING ME".to_string()
};

let mut router = Router::new();
router.get("/", echo, "index");

Iron::new(router).http("localhost:3000").unwrap();
}

+ 47
- 0
src/main_hyper.rs.bak View File

@@ -0,0 +1,47 @@
extern crate hyper;
extern crate reroute;
extern crate rss;

use hyper::server::{Server, Request, Response, Handler};
use reroute::{Router, Captures};

mod broadcast;
mod bassdrive;

#[allow(unused)]
fn http_404(req: Request, res: Response) {
res.send(format!("Couldn't find URL: {}", req.uri).as_bytes());
}

struct EchoHandler {
response: String
}

impl EchoHandler {
fn handle(&self, _: Request, res: Response, _: Captures) {
res.send(self.response.as_bytes());
}
}


#[allow(unused)]
fn main() {
let mut router = Router::new();

let echo = EchoHandler {
response: "Hello, world!".to_string()
};
router.get(r"/hello", echo);

/*
router.get(r"/hello", build_broadcast(
BassDrive {
url: "http://archives.bassdrivearchive.com/6%20-%20Saturday/Electronic%20Warfare%20-%20The%20Overfiend/"
})
);
*/
router.add_not_found(http_404);
router.finalize().unwrap();

Server::http("0.0.0.0:3000").unwrap().handle(router).unwrap();
}

Loading…
Cancel
Save