Compare commits
106 commits
Author | SHA1 | Date | |
---|---|---|---|
e06202941f | |||
|
db523065e0 | ||
|
3f87d011e7 | ||
|
26c46227e6 | ||
|
05d4233d3f | ||
|
2a9c2cef76 | ||
|
ee426b1a43 | ||
|
97f794a36e | ||
|
0c1f4ba125 | ||
|
f1a2ae0311 | ||
|
e2f2015e06 | ||
|
4bd50bdadf | ||
|
28d34eb85d | ||
|
2c8b4776d9 | ||
|
6aa876047a | ||
|
9a12ffc5fc | ||
|
7ab30ce7c3 | ||
|
6d50289a35 | ||
|
3941fe6a1f | ||
|
b853a6acec | ||
|
5d372a60de | ||
|
1a89052244 | ||
|
1f659c13ab | ||
|
d6ea7a689e | ||
|
5a5942c480 | ||
|
70e801e03c | ||
|
766156841b | ||
|
da790827d4 | ||
|
cb915104cb | ||
|
856cce5c03 | ||
|
1a5bd83c1e | ||
|
0a69149418 | ||
|
2820a223b4 | ||
|
362a4cd064 | ||
|
6e8d6b6e63 | ||
|
4179c0c716 | ||
|
17860073ec | ||
|
8019e1e247 | ||
|
d9d3dd6bf7 | ||
|
5b2365e925 | ||
|
961c02bcf9 | ||
|
1af6efe6e2 | ||
|
fcf7e37076 | ||
|
19070a34b8 | ||
|
1e5a6defe2 | ||
|
7b8d4a32df | ||
|
ef62a42e14 | ||
|
87e22a6efc | ||
|
e99b290c26 | ||
|
2167b80e63 | ||
|
066233d1ed | ||
|
f710a77230 | ||
|
6ffa2b739c | ||
|
870ac63268 | ||
|
decaab505d | ||
|
1b5aa6396a | ||
|
75ceb6061c | ||
|
d135d5869d | ||
|
68a78fbaa3 | ||
|
3daf1c7ccf | ||
|
18e606baa8 | ||
|
cdce2e3048 | ||
|
8b9b16aa2e | ||
|
c6101c1e9e | ||
|
3fa43fa798 | ||
|
b352ee0e67 | ||
|
d9532aa17a | ||
|
5fc345c0de | ||
|
dbe6a60417 | ||
|
e931692d33 | ||
|
41d2bb484e | ||
|
de4785cc29 | ||
|
c231f792f2 | ||
|
af08c9a7ce | ||
|
ec0b626ed8 | ||
|
5b0798277d | ||
|
2c02c6fdaf | ||
|
c52269835b | ||
|
be47ad0bab | ||
|
6cd663f559 | ||
|
58228eeddb | ||
|
1ba7a4bc43 | ||
|
c467d164cf | ||
|
b961de0eec | ||
|
b51a3e44d0 | ||
|
32da1e8aef | ||
|
191d0ab7e2 | ||
|
d52e8761a9 | ||
|
613e34beeb | ||
|
e753a6169d | ||
|
86b4cfec69 | ||
|
b47fefcbf5 | ||
|
b8b8d82104 | ||
|
18ba93c44e | ||
|
8bc1fee17d | ||
|
d431f07784 | ||
|
b4a93ca669 | ||
|
e684533f8e | ||
|
d15458ca51 | ||
|
adc3dbb710 | ||
|
b8636bc4fc | ||
|
e4f0032f1a | ||
|
a5931336f2 | ||
|
b3f58576c6 | ||
|
37ddea7767 | ||
|
a2099da6a0 |
14 changed files with 396 additions and 53 deletions
44
.forgejo/workflows/build-image.yml
Normal file
44
.forgejo/workflows/build-image.yml
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '30 1 * * *'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: ubuntu:latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: login to docker registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: git.ragarock.moe
|
||||||
|
username: silvana
|
||||||
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
- name: setup buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: build and push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
tags: git.ragarock.moe/${{ env.GITHUB_REPOSITORY }}:latest
|
||||||
|
|
||||||
|
# - name: Clear image from cache
|
||||||
|
# run: |
|
||||||
|
# docker images git.ragarock.moe/${{ env.GITHUB_REPOSITORY }} -q | sort -u | xargs -r docker rmi --force
|
||||||
|
# docker system prune --force --all
|
||||||
|
|
||||||
|
# - name: Build
|
||||||
|
# run: docker build . -t git.ragarock.moe/${{ env.GITHUB_REPOSITORY }}:latest
|
||||||
|
|
||||||
|
# - name: Login
|
||||||
|
# run: docker login git.ragarock.moe --username silvana --password ${{ secrets.FORGEJO_TOKEN_WRITE_PACKAGE }}
|
||||||
|
|
||||||
|
# - name: Publish
|
||||||
|
# run: docker push git.ragarock.moe/${{ env.GITHUB_REPOSITORY }}:latest
|
45
.forgejo/workflows/push-next.yml
Normal file
45
.forgejo/workflows/push-next.yml
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- next
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: git.ragarock.moe/silvana/rust:latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
toolchain:
|
||||||
|
- name: stable
|
||||||
|
- name: nightly
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Ignored Files
|
||||||
|
run: check-for-ignored
|
||||||
|
# run: |
|
||||||
|
# IGNORED=$(git ls-files --cached -i --exclude-standard)
|
||||||
|
# if [ -n "$IGNORED" ]
|
||||||
|
# then
|
||||||
|
# echo "Ignored files present:\n$IGNORED"
|
||||||
|
# exit 1
|
||||||
|
# fi
|
||||||
|
|
||||||
|
- name: Machete
|
||||||
|
run: cargo machete
|
||||||
|
|
||||||
|
- name: Format
|
||||||
|
run: cargo +${{ matrix.toolchain.name }} fmt --check
|
||||||
|
|
||||||
|
- name: Clippy
|
||||||
|
run: cargo +${{ matrix.toolchain.name }} clippy
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: cargo +${{ matrix.toolchain.name }} test
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: cargo +${{ matrix.toolchain.name }} build
|
||||||
|
|
||||||
|
- name: Run
|
||||||
|
run: cargo +${{ matrix.toolchain.name }} run
|
|
@ -1,9 +0,0 @@
|
||||||
on: [push]
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: docker
|
|
||||||
steps:
|
|
||||||
- name: Test Rust image
|
|
||||||
uses: https://git.kemitix.net/kemitix/rust@v0.1.0
|
|
||||||
with:
|
|
||||||
args: test
|
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/target
|
||||||
|
Cargo.lock
|
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "rust"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
kxio = "5.1"
|
||||||
|
tokio = { version = "1.43", features = ["full"] }
|
64
Dockerfile
64
Dockerfile
|
@ -1,26 +1,56 @@
|
||||||
FROM docker.io/rust:1.78.0-slim-bookworm
|
FROM docker.io/rust:1.84.0-alpine3.21
|
||||||
|
|
||||||
# nodejs - runtime used by forgejo/github actions
|
LABEL org.opencontainers.image.source=https://git.ragarock.moe/silvana/rust
|
||||||
# curl - to download cargo-binstall
|
|
||||||
# clang-16 & mold - faster linkers for rust
|
|
||||||
RUN apt-get update && \
|
|
||||||
apt-get install -y \
|
|
||||||
--no-install-recommends \
|
|
||||||
nodejs \
|
|
||||||
curl=7.88.1-10+deb12u5 \
|
|
||||||
clang-16=1:16.0.6-15~deb12u1 \
|
|
||||||
mold=1.10.1+dfsg-1 && \
|
|
||||||
rm -r /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
RUN curl -L https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz -o cargo-binstall.tgz && \
|
RUN apk add --no-cache curl=8.11.1-r0
|
||||||
|
RUN curl -L https://github.com/cargo-bins/cargo-binstall/releases/download/v1.10.19/cargo-binstall-x86_64-unknown-linux-musl.tgz -o cargo-binstall.tgz && \
|
||||||
tar -xzf cargo-binstall.tgz && \
|
tar -xzf cargo-binstall.tgz && \
|
||||||
rm cargo-binstall.tgz && \
|
rm cargo-binstall.tgz && \
|
||||||
mv cargo-binstall /usr/local/bin/
|
mv cargo-binstall /usr/local/bin/
|
||||||
|
|
||||||
RUN cargo binstall -y cargo-chef
|
RUN cargo binstall -y \
|
||||||
|
cargo-chef@0.1 \
|
||||||
|
cargo-hack@0.6 \
|
||||||
|
cargo-machete@0.7 \
|
||||||
|
cargo-mutants@25.0 \
|
||||||
|
release-plz@0.3
|
||||||
|
|
||||||
RUN rustup component add rustfmt clippy
|
# should be a no-op if the FROM line is up-to-date
|
||||||
|
RUN rustup update stable
|
||||||
|
|
||||||
COPY entrypoint.sh /
|
RUN rustup component add --toolchain stable-x86_64-unknown-linux-musl rustfmt clippy
|
||||||
|
|
||||||
ENTRYPOINT [ "/entrypoint.sh" ]
|
# install nightly
|
||||||
|
RUN rustup install nightly && rustup component add --toolchain nightly rustfmt clippy
|
||||||
|
|
||||||
|
# nodejs - runtime used by forgejo/github actions
|
||||||
|
# curl - to download cargo-binstall
|
||||||
|
# clang & mold - faster linkers for rust
|
||||||
|
# pkgconfig - required to compile some rust `-sys` packages
|
||||||
|
# openssl-dev - build dependency for git-next
|
||||||
|
# dbus-dev - linux os interop (e.g. desktop notifications)
|
||||||
|
# perl - native-tls(vendored)
|
||||||
|
# git - git
|
||||||
|
RUN apk add --no-cache \
|
||||||
|
bash \
|
||||||
|
nodejs \
|
||||||
|
build-base \
|
||||||
|
pkgconfig \
|
||||||
|
libssl3 \
|
||||||
|
openssl-dev \
|
||||||
|
perl \
|
||||||
|
dbus-dev \
|
||||||
|
git
|
||||||
|
|
||||||
|
# clang \
|
||||||
|
|
||||||
|
# mold \
|
||||||
|
|
||||||
|
# dbus-dev \
|
||||||
|
|
||||||
|
RUN git config --global user.email "holo@ragarock.moe" && \
|
||||||
|
git config --global user.name "ForgeJo Action. See: https://git.ragarock.moe/silvana/rust"
|
||||||
|
|
||||||
|
COPY scripts/ /usr/local/bin/
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
83
README.md
83
README.md
|
@ -11,41 +11,84 @@ on: [push]
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image:
|
||||||
|
git.kemitix.net/kemitix/rust:v3.0.0
|
||||||
steps:
|
steps:
|
||||||
- uses: https://git.kemitix.net/kemitix/rust@main
|
- name: test with nightly
|
||||||
with:
|
run: cargo +nightly test
|
||||||
args: test
|
- name: build with v1.74.1
|
||||||
- uses: https://git.kemitix.net/kemitix/rust@main
|
run: cargo +1.74.1 cargo build
|
||||||
with:
|
- name: test with stable
|
||||||
args: build
|
run: cargo test
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Toolchains
|
||||||
|
|
||||||
|
The available toolchain in the image are:
|
||||||
|
|
||||||
|
- `nightly`
|
||||||
|
- stable
|
||||||
|
- 1.74.1
|
||||||
|
|
||||||
## Contents
|
## Contents
|
||||||
|
|
||||||
- nodejs
|
- nodejs
|
||||||
- clang-16
|
|
||||||
- mold
|
|
||||||
- rust
|
- rust
|
||||||
|
- git
|
||||||
- cargo
|
- cargo
|
||||||
- cargo-binstall
|
- cargo-binstall
|
||||||
|
- cargo-mutants
|
||||||
|
- cargo-chef
|
||||||
|
- cargo-hack
|
||||||
|
- release-plz
|
||||||
|
- dbus-dev
|
||||||
|
- perl
|
||||||
|
|
||||||
## Linking
|
### Scripts
|
||||||
|
|
||||||
To take advantage of the clang and mold packages, add the following to the `.cargo/config.toml` file in your project.
|
- `check-for-ignored`
|
||||||
|
|
||||||
```toml
|
Checks for files that are being tracked by Git but should be ignored according
|
||||||
[target.x86_64-unknown-linux-gnu]
|
to the `.gitignore` file.
|
||||||
linker = "/usr/bin/clang-16"
|
|
||||||
rustflags = ["-C", "link-arg=--ld-path=/usr/bin/mold"]
|
#### Usage
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- name: Check for Ignored Files
|
||||||
|
run: check-for-ignored
|
||||||
```
|
```
|
||||||
|
|
||||||
## Binary size
|
## Caveats
|
||||||
|
|
||||||
To reduce the size of the debug binary, add the following to the `.cargo/config.toml` file in you project.
|
### openssl
|
||||||
|
|
||||||
|
The alpine linux install doesn't build with this dependency. You can either compile `native-tls` with the `vendored` feature, or not use `openssl`.
|
||||||
|
|
||||||
|
#### vendoered native-tls
|
||||||
|
|
||||||
|
This crate *must* use the `vendored` feature in order to compile in the Alpine Linux image.
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[profile.dev]
|
native-tls = { version = "0.2", features = ["vendored"] }
|
||||||
debug = 0
|
```
|
||||||
strip = "debuginfo"
|
|
||||||
|
#### Don't use `openssl`
|
||||||
|
|
||||||
|
Check that none of your dependencies require `openssl`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo tree --edges normal -i openssl
|
||||||
|
```
|
||||||
|
|
||||||
|
This will list the tree of dependencies that are bringing in `openssl`.
|
||||||
|
|
||||||
|
If you do need ssl/tls, try using `rustls`. e.g.
|
||||||
|
|
||||||
|
```toml
|
||||||
|
reqwest = { version = "0.12", default-features = false, features = [
|
||||||
|
"json",
|
||||||
|
"rustls-tls",
|
||||||
|
] }
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# set
|
|
||||||
ls -l
|
|
||||||
echo cargo ${INPUT_ARGS}
|
|
19
justfile
Normal file
19
justfile
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
image := "git.ragarock.moe/silvana/rust:test"
|
||||||
|
|
||||||
|
build:
|
||||||
|
docker build . -t {{ image }}
|
||||||
|
|
||||||
|
test: build
|
||||||
|
docker run --rm -v $PWD:/app/ {{ image }} cargo test
|
||||||
|
|
||||||
|
clippy: build
|
||||||
|
docker run --rm -v $PWD:/app/ {{ image }} cargo clippy
|
||||||
|
|
||||||
|
run: build
|
||||||
|
docker run --rm -v $PWD:/app/ {{ image }} cargo run
|
||||||
|
|
||||||
|
fmt: build
|
||||||
|
docker run --rm -v $PWD:/app/ {{ image }} cargo fmt
|
||||||
|
|
||||||
|
shell: build
|
||||||
|
docker run --rm -it -v $PWD:/app/ {{ image }} bash
|
10
mise.toml
Normal file
10
mise.toml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[tasks.test]
|
||||||
|
description = "Test the image"
|
||||||
|
run = [
|
||||||
|
"cargo machete",
|
||||||
|
"cargo fmt --check",
|
||||||
|
"cargo clippy",
|
||||||
|
"cargo test",
|
||||||
|
"cargo build",
|
||||||
|
"cargo run"
|
||||||
|
]
|
6
renovate.json
Normal file
6
renovate.json
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": [
|
||||||
|
"config:recommended"
|
||||||
|
]
|
||||||
|
}
|
30
scripts/check-for-ignored
Executable file
30
scripts/check-for-ignored
Executable file
|
@ -0,0 +1,30 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Exit on error
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Check if git is installed
|
||||||
|
if ! command -v git &> /dev/null; then
|
||||||
|
echo "Error: git is not installed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if we're in a git repository
|
||||||
|
if ! git rev-parse --is-inside-work-tree &> /dev/null; then
|
||||||
|
echo "Error: not in a git repository"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Checking for tracked files that should be ignored..."
|
||||||
|
|
||||||
|
# Find files that are both tracked and ignored
|
||||||
|
ignored_files=$(git ls-files --cached -i --exclude-standard)
|
||||||
|
|
||||||
|
if [[ -z "$ignored_files" ]]; then
|
||||||
|
echo "No tracked files are marked as ignored"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "The following tracked files are marked as ignored:"
|
||||||
|
echo "$ignored_files"
|
||||||
|
exit 1
|
||||||
|
fi
|
105
src/kxio.rs
Normal file
105
src/kxio.rs
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
/// This is an example to show fetching a file from a webiste and saving to a file
|
||||||
|
///
|
||||||
|
/// The example consts of:
|
||||||
|
///
|
||||||
|
/// - The main program, in `main()` - demonstrates how to setup `kxio` for use in prod
|
||||||
|
/// - A test module - demonstrates how to use `kxio` in tests
|
||||||
|
/// - sample functions - showing how to use `kxio` the body of your program, and be testable
|
||||||
|
///
|
||||||
|
/// NOTE: running this program with `cargo run --example get` will create and delete the file
|
||||||
|
/// `example-readme.md` in the current directory.
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use kxio::fs::FileHandle;
|
||||||
|
|
||||||
|
// #[tokio::main]
|
||||||
|
pub async fn main() -> kxio::Result<()> {
|
||||||
|
// Create a `Net` object for making real network requests.
|
||||||
|
let net: kxio::net::Net = kxio::net::new();
|
||||||
|
|
||||||
|
// Create a `FileSystem` object for accessing files within the current directory.
|
||||||
|
// The object created will return a `PathTraveral` error result if there is an attempt to\
|
||||||
|
// access a file outside of this directory.
|
||||||
|
let current_dir = std::env::current_dir().map_err(kxio::fs::Error::Io)?;
|
||||||
|
let fs: kxio::fs::FileSystem = kxio::fs::new(current_dir);
|
||||||
|
|
||||||
|
// The URL we will fetch - the readme for this library.
|
||||||
|
let url = "https://git.kemitix.net/kemitix/kxio/raw/branch/main/README.md";
|
||||||
|
|
||||||
|
// Create a PathBuf to a file within the directory that the `fs` object has access to.
|
||||||
|
let file_path = fs.base().join("example-readme.md");
|
||||||
|
|
||||||
|
// Create a generic handle for the file. This doesn't open the file, and always succeeds.
|
||||||
|
let path = fs.path(&file_path);
|
||||||
|
|
||||||
|
// Other options are;
|
||||||
|
// `fs.file(&file_path)` - for a file
|
||||||
|
// `fs.dir(&dir_path)` - for a directory
|
||||||
|
|
||||||
|
// Checks if the path exists (whether a file, directory, etc)
|
||||||
|
if path.exists()? {
|
||||||
|
eprintln!("The file {path} already exists. Aborting!");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Passes a reference to the `fs` and `net` objects for use by your program.
|
||||||
|
// Your programs should not know whether they are handling a mock or the real thing.
|
||||||
|
// Any file or network access should be made using these handlers to be properly testable.
|
||||||
|
let file = download_and_save_to_file(url, &file_path, &fs, &net).await?;
|
||||||
|
read_file(&file)?;
|
||||||
|
delete_file(file)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An function that uses a `FileSystem` and a `Net` object to interact with the outside world.
|
||||||
|
async fn download_and_save_to_file(
|
||||||
|
url: &str,
|
||||||
|
file_path: &Path,
|
||||||
|
// The filesystem abstraction
|
||||||
|
fs: &kxio::fs::FileSystem,
|
||||||
|
// The network abstraction
|
||||||
|
net: &kxio::net::Net,
|
||||||
|
) -> kxio::Result<FileHandle> {
|
||||||
|
println!("fetching: {url}");
|
||||||
|
|
||||||
|
// Makes a GET request that can be mocked in a test
|
||||||
|
let response = net.get(url).header("key", "value").send().await?;
|
||||||
|
|
||||||
|
// As you can see, we use [reqwest] under the hood.
|
||||||
|
//
|
||||||
|
// If you need to create a more complex request than the [kxio] fluent API allows, you
|
||||||
|
// can create a request using [reqwest] and pass it to [net.send(request)].
|
||||||
|
|
||||||
|
let body = response.text().await?;
|
||||||
|
println!("fetched {} bytes", body.bytes().len());
|
||||||
|
|
||||||
|
// Uses the file system abstraction to create a handle for a file.
|
||||||
|
let file: kxio::fs::PathReal<kxio::fs::FileMarker> = fs.file(file_path);
|
||||||
|
println!("writing file: {file}");
|
||||||
|
// Writes the body to the file.
|
||||||
|
file.write(body)?;
|
||||||
|
|
||||||
|
Ok(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A function that reads the file contents
|
||||||
|
fn read_file(file: &FileHandle) -> kxio::Result<()> {
|
||||||
|
println!("reading file: {file}");
|
||||||
|
|
||||||
|
// Creates a `Reader` which loaded the file into memory.
|
||||||
|
let reader: kxio::fs::Reader = file.reader()?;
|
||||||
|
let contents: &str = reader.as_str()?;
|
||||||
|
println!("{contents}");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A function that deletes the file
|
||||||
|
fn delete_file(file: FileHandle) -> kxio::Result<()> {
|
||||||
|
println!("deleting file: {file}");
|
||||||
|
|
||||||
|
file.remove()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
17
src/main.rs
Normal file
17
src/main.rs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
//
|
||||||
|
mod kxio;
|
||||||
|
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
println!("Hello, world!");
|
||||||
|
|
||||||
|
let rt = tokio::runtime::Runtime::new()?;
|
||||||
|
Ok(rt.block_on(crate::kxio::main())?)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn passes() {
|
||||||
|
println!("passes okay");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue