initial commit
This commit is contained in:
commit
3b34c44084
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
141
Cargo.lock
generated
Normal file
141
Cargo.lock
generated
Normal file
@ -0,0 +1,141 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "instant"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.88"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a"
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312"
|
||||
dependencies = [
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb"
|
||||
dependencies = [
|
||||
"instant",
|
||||
"lock_api",
|
||||
"parking_lot_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot_core"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"instant",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"smallvec",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pixelrush"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"r2d2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r2d2"
|
||||
version = "0.8.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "545c5bc2b880973c9c10e4067418407a0ccaa3091781d1671d46eb35107cb26f"
|
||||
dependencies = [
|
||||
"log",
|
||||
"parking_lot",
|
||||
"scheduled-thread-pool",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scheduled-thread-pool"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc6f74fd1204073fa02d5d5d68bec8021be4c38690b61264b2fdb48083d0e7d7"
|
||||
dependencies = [
|
||||
"parking_lot",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "pixelrush"
|
||||
version = "0.1.0"
|
||||
authors = ["Huanzo <huanzodev@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
r2d2 = "*"
|
9
drone.yml
Normal file
9
drone.yml
Normal file
@ -0,0 +1,9 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: check
|
||||
|
||||
steps:
|
||||
- name: Cargo check
|
||||
image: rust:latest
|
||||
commands:
|
||||
- cargo check
|
11
src/main.rs
Normal file
11
src/main.rs
Normal file
@ -0,0 +1,11 @@
|
||||
mod pixelflut;
|
||||
|
||||
use pixelflut::*;
|
||||
|
||||
fn main() -> Result<(), std::io::Error>{
|
||||
let manager = PixelflutConnectionManager::new("localhost:1234")?;
|
||||
let pool = r2d2::Pool::builder()
|
||||
.max_size(15)
|
||||
.build(manager).expect("Could not initialize connection pool");
|
||||
Ok(())
|
||||
}
|
67
src/pixelflut.rs
Normal file
67
src/pixelflut.rs
Normal file
@ -0,0 +1,67 @@
|
||||
use r2d2::ManageConnection;
|
||||
use std::{io::Error, net::{SocketAddr, TcpStream}};
|
||||
use std::io::Write;
|
||||
|
||||
pub struct PixelflutConnectionManager {
|
||||
addr: SocketAddr
|
||||
}
|
||||
|
||||
pub struct PixelflutConnection {
|
||||
stream: TcpStream
|
||||
}
|
||||
|
||||
impl PixelflutConnectionManager {
|
||||
pub fn new(addr: &str) -> Result<Self, Error> {
|
||||
let addr: SocketAddr = match addr.parse() {
|
||||
Ok(addr) => addr,
|
||||
Err(e) => panic!("Error in parsing the socket address: {}", e)
|
||||
};
|
||||
Ok(Self {addr})
|
||||
}
|
||||
|
||||
fn get_connection(&self) -> Result<PixelflutConnection, Error> {
|
||||
let stream = TcpStream::connect(self.addr)?;
|
||||
Ok(PixelflutConnection {stream})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct Rgba(pub u32);
|
||||
|
||||
impl From<u32> for Rgba {
|
||||
fn from(a: u32) -> Self {
|
||||
Self(a)
|
||||
}
|
||||
}
|
||||
|
||||
impl PixelflutConnection {
|
||||
#[inline]
|
||||
pub fn new(addr: SocketAddr) -> Result<Self, Error> {
|
||||
let stream = TcpStream::connect(addr)?;
|
||||
Ok(Self {stream})
|
||||
}
|
||||
|
||||
pub fn set(&mut self, x: usize, y: usize, c: impl Into<Rgba>) {
|
||||
let msg = format!("PX {} {} {}\n", x,y,12);
|
||||
self.stream.write(&msg[..].as_bytes());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl ManageConnection for PixelflutConnectionManager {
|
||||
type Connection = PixelflutConnection;
|
||||
type Error = Error;
|
||||
|
||||
fn connect(&self) -> Result<Self::Connection, Self::Error> {
|
||||
self.get_connection()
|
||||
}
|
||||
|
||||
fn is_valid(&self, conn: &mut Self::Connection) -> Result<(), Self::Error> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn has_broken(&self, conn: &mut Self::Connection) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user