Remove main file and add direnv configuration
This commit is contained in:
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
flake-profile-1-link
|
||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
/nix/store/ag9rnmlp7b4mq8jcnzvnk6nij4gjxak5-nix-shell-env
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# EditorConfig for Rust template
|
||||||
|
root = false
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
trim_trailing_whitespace = true
|
||||||
Generated
+1
@@ -3,6 +3,7 @@
|
|||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v4.4.0
|
||||||
|
hooks:
|
||||||
|
- id: trailing-whitespace
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- id: check-yaml
|
||||||
|
- id: check-added-large-files
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
Thank you for considering contributing!
|
||||||
|
|
||||||
|
- Please follow the project coding style and directory structure.
|
||||||
|
- Submit issues or pull requests for bugs, features, or improvements.
|
||||||
|
- Add tests for new features where possible.
|
||||||
|
- Ensure your code builds and passes tests before submitting.
|
||||||
|
- Contributions are licensed under CC BY-SA 4.0.
|
||||||
Generated
+9
@@ -5,3 +5,12 @@ version = 4
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "kt_log"
|
name = "kt_log"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.4.33"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad"
|
||||||
|
|||||||
@@ -2,5 +2,14 @@
|
|||||||
name = "kt_log"
|
name = "kt_log"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
description = "A console logging library for Rust applications"
|
||||||
|
license = "MIT"
|
||||||
|
publish = ["gitea"]
|
||||||
|
autobins = false
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "kt_log"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
log = "0.4"
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
Creative Commons Attribution-ShareAlike 4.0 International
|
||||||
|
|
||||||
|
<https://creativecommons.org/licenses/by-sa/4.0/>
|
||||||
|
|
||||||
|
You are free to:
|
||||||
|
|
||||||
|
- Share — copy and redistribute the material in any medium or format
|
||||||
|
- Adapt — remix, transform, and build upon the material for any purpose, even commercially.
|
||||||
|
|
||||||
|
Under the following terms:
|
||||||
|
|
||||||
|
- Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made.
|
||||||
|
- ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
|
||||||
|
|
||||||
|
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
|
||||||
|
|
||||||
|
See the full license at the link above.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
build:
|
||||||
|
cargo build
|
||||||
|
|
||||||
|
run:
|
||||||
|
cargo run
|
||||||
|
|
||||||
|
test:
|
||||||
|
cargo test
|
||||||
|
|
||||||
|
clean:
|
||||||
|
cargo clean
|
||||||
|
|
||||||
|
.PHONY: build run test clean
|
||||||
|
|
||||||
|
|
||||||
|
# Flatpak build target
|
||||||
|
.PHONY: flatpak-build
|
||||||
|
flatpak-build:
|
||||||
|
flatpak-builder --force-clean build-flatpak flatpak/app.flatpak.json
|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
# Rust Nix Flake Template
|
||||||
|
|
||||||
|
This template provides a reproducible Rust development environment using Nix flakes and the fenix toolchain.
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nix develop
|
||||||
|
# or with direnv:
|
||||||
|
direnv allow
|
||||||
|
```
|
||||||
|
|
||||||
|
### Automatic Environment Setup
|
||||||
|
|
||||||
|
When you enter the devShell (via `direnv allow` or `nix develop`), the following happens automatically:
|
||||||
|
|
||||||
|
✓ **Git Repository**: Initializes `.git` if not present
|
||||||
|
✓ **Rust Targets**: Automatically adds common embedded Rust targets (ARM Cortex-M, RISC-V)
|
||||||
|
✓ **Cargo Paths**: Sets up `$HOME/.cargo/bin` in PATH for cargo-installed binaries
|
||||||
|
✓ **Welcome Banner**: Displays available tools and quick commands
|
||||||
|
|
||||||
|
No manual setup needed! Just start coding.
|
||||||
|
|
||||||
|
## Quickstart
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nix flake init -t path:../flakes#rust
|
||||||
|
nix develop
|
||||||
|
cargo build
|
||||||
|
```
|
||||||
|
|
||||||
|
## Embedded Rust Support
|
||||||
|
|
||||||
|
The devShell automatically installs common embedded Rust targets via `rustup`:
|
||||||
|
|
||||||
|
| Target | Platform | Use Case |
|
||||||
|
|--------|----------|----------|
|
||||||
|
| `thumbv6m-none-eabi` | ARM Cortex-M0/M0+ | RP2040 (Pico) |
|
||||||
|
| `thumbv7em-none-eabihf` | ARM Cortex-M4F/M7F | STM32, nRF52840 |
|
||||||
|
| `riscv32imc-unknown-none-elf` | RISC-V 32-bit | ESP32-C3 (basic) |
|
||||||
|
| `riscv32imac-unknown-none-elf` | RISC-V 32-bit (atomic) | ESP32-C3 (advanced) |
|
||||||
|
|
||||||
|
**Note:** ESP32 Xtensa targets require espup or custom toolchains (see [esp-rs](https://github.com/esp-rs)).
|
||||||
|
|
||||||
|
## Flatpak Packaging
|
||||||
|
|
||||||
|
This template supports building Flatpak packages for your Rust application.
|
||||||
|
|
||||||
|
### Build Flatpak Package
|
||||||
|
|
||||||
|
1. Ensure you have `flatpak-builder` installed.
|
||||||
|
2. Run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make flatpak-build
|
||||||
|
```
|
||||||
|
|
||||||
|
This will use the manifest at `flatpak/app.flatpak.json` to build a Flatpak bundle in the `build-flatpak/` directory.
|
||||||
|
|
||||||
|
### Customize Manifest
|
||||||
|
|
||||||
|
Edit `flatpak/app.flatpak.json` to update app ID, runtime, build commands, or sources as needed for your project.
|
||||||
|
|
||||||
|
### Install/Run Flatpak Locally
|
||||||
|
|
||||||
|
You can install and run the built Flatpak locally:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
flatpak install --user build-flatpak/org.example.rustdevshell.flatpak
|
||||||
|
flatpak run org.example.rustdevshell
|
||||||
|
```
|
||||||
|
|
||||||
|
## Included Tools
|
||||||
|
|
||||||
|
| Tool | Purpose |
|
||||||
|
|------|---------|
|
||||||
|
| **cargo** | Rust package manager and build system |
|
||||||
|
| **rustc** | Rust compiler |
|
||||||
|
| **clippy** | Rust linter for catching common mistakes |
|
||||||
|
| **rustfmt** | Rust code formatter |
|
||||||
|
| **rust-analyzer** | Language server for IDE integration |
|
||||||
|
| **rust-src** | Rust source code (for tools like rust-analyzer) |
|
||||||
|
| **probe-rs** | Embedded debugger/flasher for ARM targets |
|
||||||
|
| **espflash** | Flashing tool for ESP32 boards |
|
||||||
|
| **openocd** | JTAG/SWD debugger for ARM and other targets |
|
||||||
|
| **minicom** | Serial terminal for device output |
|
||||||
|
| **elf2uf2-rs** | Convert ELF to UF2 format (RP2040) |
|
||||||
|
| **picotool** | Pico-specific firmware operations |
|
||||||
|
| **avrdude** | AVR microcontroller programmer |
|
||||||
|
| **ravedude** | Rapid AVR development utility |
|
||||||
|
|
||||||
|
## Testing & Development Features
|
||||||
|
|
||||||
|
Build and testing tools:
|
||||||
|
|
||||||
|
- **cargo test** - Run unit and integration tests
|
||||||
|
- **cargo clippy** - Lint code for common issues
|
||||||
|
- **cargo fmt** - Format code consistently with rustfmt
|
||||||
|
|
||||||
|
**Example usage:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run tests
|
||||||
|
cargo test
|
||||||
|
|
||||||
|
# Check code with clippy
|
||||||
|
cargo clippy
|
||||||
|
|
||||||
|
# Format code
|
||||||
|
cargo fmt
|
||||||
|
|
||||||
|
# Build for embedded target
|
||||||
|
cargo build --target thumbv7em-none-eabihf --release
|
||||||
|
```
|
||||||
|
|
||||||
|
## Project Layout
|
||||||
|
|
||||||
|
```
|
||||||
|
Cargo.toml
|
||||||
|
Cargo.lock
|
||||||
|
src/
|
||||||
|
└── main.rs (or lib.rs)
|
||||||
|
Makefile
|
||||||
|
.envrc
|
||||||
|
flake.nix
|
||||||
|
```
|
||||||
|
|
||||||
|
## Legacy Usage
|
||||||
|
|
||||||
|
If you do not use flakes, run:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nix-shell
|
||||||
|
```
|
||||||
|
|
||||||
|
## Project Metadata
|
||||||
|
|
||||||
|
See project.toml for example metadata.
|
||||||
|
|
||||||
|
## Helper Tools
|
||||||
|
|
||||||
|
- **`nix run .#dev-helper`** - Display tool versions and availability
|
||||||
|
- **`cargo build`** - Build the project
|
||||||
|
- **`cargo check`** - Quick syntax check without building
|
||||||
|
- **`cargo doc --open`** - Generate and view documentation
|
||||||
|
|
||||||
|
## Packaging for nixpkgs
|
||||||
|
|
||||||
|
This template is structured for easy packaging in nixpkgs:
|
||||||
|
|
||||||
|
- All sources in `src/`
|
||||||
|
- `flake.nix` provides a devShell and template
|
||||||
|
- Add a `default.nix` or package expression as needed for nixpkgs
|
||||||
|
|
||||||
|
See [nixpkgs Rust packaging docs](https://nixos.org/manual/nixpkgs/stable/#rust) for more details.
|
||||||
|
|
||||||
|
## Customization
|
||||||
|
|
||||||
|
Edit `flake.nix` to:
|
||||||
|
|
||||||
|
- Add additional Rust targets via `rustup target add [target]`
|
||||||
|
- Include additional cargo plugins
|
||||||
|
- Add board-specific tools (e.g., stm32cube, nrfjprog)
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
# Coding Agent Instructions
|
||||||
|
|
||||||
|
This project is intended for educational purposes. To support this, please adhere to the following guidelines:
|
||||||
|
|
||||||
|
## Allowed Actions
|
||||||
|
- **Environment Maintenance:** Feel free to update Nix flakes, shell configurations, or other environment-related setup.
|
||||||
|
- **Project Housekeeping:** Maintain a standard project layout, keep `README.md` up-to-date, and clean up temporary or build-related files.
|
||||||
|
- **Documentation:** Add comments, manage project documentation, and add links to relevant external resources.
|
||||||
|
|
||||||
|
## Restricted Actions
|
||||||
|
- **Source Code Editing:** You are NOT allowed to edit the executable source code (`src/` directory) except to improve documentation..
|
||||||
|
- **Code Generation:** Do not provide example code unless explicitly asked by the user.
|
||||||
|
|
||||||
|
## Communication Guidelines
|
||||||
|
- **Educational Focus:** When asked about code, prioritize explaining the concepts and providing advice over writing code.
|
||||||
|
- **Documentation Links:** Always include links to official language or library documentation for references.
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
{ pkgs }:
|
||||||
|
let
|
||||||
|
lib = pkgs.lib;
|
||||||
|
templateName = builtins.baseNameOf (toString ./.);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
${templateName} = pkgs.stdenvNoCC.mkDerivation {
|
||||||
|
pname = templateName;
|
||||||
|
version = "0.1.0";
|
||||||
|
src = ./.;
|
||||||
|
dontBuild = true;
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/share/${templateName}
|
||||||
|
if [ -d src ]; then
|
||||||
|
cp -r src $out/share/${templateName}/
|
||||||
|
fi
|
||||||
|
for f in README.md project.toml flake.nix default.nix shell.nix Makefile .editorconfig .gitignore; do
|
||||||
|
if [ -f "$f" ]; then
|
||||||
|
cp "$f" $out/share/${templateName}/
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
meta = with lib; {
|
||||||
|
description = "Template project: ${templateName}";
|
||||||
|
license = licenses.unfreeRedistributable;
|
||||||
|
platforms = platforms.all;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Generated
+66
@@ -0,0 +1,66 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"fenix": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
],
|
||||||
|
"rust-analyzer-src": "rust-analyzer-src"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1787208815,
|
||||||
|
"narHash": "sha256-SiyWmwDoDF2jCEpEW887qxaUazaQrVQs+QXq2bvgm+0=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "fenix",
|
||||||
|
"rev": "428f69c19e46334bed722164c5125b62d3722723",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "fenix",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1787135253,
|
||||||
|
"narHash": "sha256-RD2kNWCG+Bjo6h+JVjWVNntZs2GtRoeY2xHjts/FNkA=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "ffb3c9b700e759be2ef13237c9d8f953b32a1e46",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"fenix": "fenix",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rust-analyzer-src": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1787106123,
|
||||||
|
"narHash": "sha256-Usi0dFNYgdN5gXYDjLLGCYYkzW7Xl9uBhwGD5OkuWoM=",
|
||||||
|
"owner": "rust-lang",
|
||||||
|
"repo": "rust-analyzer",
|
||||||
|
"rev": "32a3346dff5b26e16227affd5af933e15ebc598b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "rust-lang",
|
||||||
|
"ref": "nightly",
|
||||||
|
"repo": "rust-analyzer",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
{
|
||||||
|
description = "Rust development environment for the kt_log console logging library";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
fenix = {
|
||||||
|
url = "github:nix-community/fenix";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs =
|
||||||
|
inputs@{ self, ... }:
|
||||||
|
let
|
||||||
|
supportedSystems = [
|
||||||
|
"x86_64-linux"
|
||||||
|
"aarch64-linux"
|
||||||
|
"x86_64-darwin"
|
||||||
|
"aarch64-darwin"
|
||||||
|
];
|
||||||
|
forEachSupportedSystem =
|
||||||
|
f:
|
||||||
|
inputs.nixpkgs.lib.genAttrs supportedSystems (
|
||||||
|
system:
|
||||||
|
f {
|
||||||
|
pkgs = import inputs.nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
overlays = [
|
||||||
|
inputs.self.overlays.default
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
templates = {
|
||||||
|
default = {
|
||||||
|
path = ./.;
|
||||||
|
description = "Rust library development environment using fenix";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
overlays.default = _final: prev: {
|
||||||
|
rustToolchain =
|
||||||
|
with inputs.fenix.packages.${prev.stdenv.hostPlatform.system};
|
||||||
|
combine (
|
||||||
|
with stable;
|
||||||
|
[
|
||||||
|
cargo
|
||||||
|
clippy
|
||||||
|
rustc
|
||||||
|
rustfmt
|
||||||
|
rust-src
|
||||||
|
]
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
devShells = forEachSupportedSystem (
|
||||||
|
{ pkgs }:
|
||||||
|
{
|
||||||
|
default = pkgs.mkShell {
|
||||||
|
packages = with pkgs; [
|
||||||
|
rustToolchain
|
||||||
|
git
|
||||||
|
gnumake
|
||||||
|
alejandra
|
||||||
|
statix
|
||||||
|
deadnix
|
||||||
|
openssl
|
||||||
|
pkg-config
|
||||||
|
cargo-deny
|
||||||
|
cargo-edit
|
||||||
|
cargo-watch
|
||||||
|
rust-analyzer
|
||||||
|
pre-commit
|
||||||
|
];
|
||||||
|
|
||||||
|
env = {
|
||||||
|
RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library";
|
||||||
|
};
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
if [ ! -d .git ]; then
|
||||||
|
git init
|
||||||
|
echo "✓ Initialized git repository"
|
||||||
|
fi
|
||||||
|
|
||||||
|
export PATH="$HOME/.cargo/bin:$PATH"
|
||||||
|
|
||||||
|
echo "[kt_log] Welcome to the Rust library development shell!"
|
||||||
|
echo "Tools: cargo, rustc, clippy, rustfmt, rust-analyzer"
|
||||||
|
echo "Run 'cargo test', 'cargo clippy', or 'cargo build' to work on the library."
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
packages = forEachSupportedSystem (
|
||||||
|
{ pkgs }:
|
||||||
|
{
|
||||||
|
default = pkgs.rustPlatform.buildRustPackage {
|
||||||
|
pname = "kt_log";
|
||||||
|
version = "0.1.0";
|
||||||
|
src = ./.;
|
||||||
|
cargoLock.lockFile = ./Cargo.lock;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
);
|
||||||
|
|
||||||
|
checks = forEachSupportedSystem (
|
||||||
|
{ pkgs }:
|
||||||
|
{
|
||||||
|
default = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
formatter = forEachSupportedSystem (
|
||||||
|
{ pkgs }:
|
||||||
|
pkgs.alejandra
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"app-id": "org.example.rustdevshell",
|
||||||
|
"runtime": "org.freedesktop.Platform",
|
||||||
|
"runtime-version": "23.08",
|
||||||
|
"sdk": "org.freedesktop.Sdk",
|
||||||
|
"command": "rustdevshell-app",
|
||||||
|
"modules": [
|
||||||
|
{
|
||||||
|
"name": "rustdevshell-app",
|
||||||
|
"buildsystem": "simple",
|
||||||
|
"build-commands": [
|
||||||
|
"cargo build --release"
|
||||||
|
],
|
||||||
|
"sources": [
|
||||||
|
{
|
||||||
|
"type": "dir",
|
||||||
|
"path": ".."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[project]
|
||||||
|
name = "rust-template"
|
||||||
|
description = "A reusable Nix flake template for Rust development."
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["gooba42 <your@email>"]
|
||||||
|
license = "MIT"
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
pkgs ? import <nixpkgs> { },
|
||||||
|
}:
|
||||||
|
pkgs.mkShell {
|
||||||
|
buildInputs = [
|
||||||
|
pkgs.rustc
|
||||||
|
pkgs.cargo
|
||||||
|
pkgs.rustfmt
|
||||||
|
pkgs.clippy
|
||||||
|
pkgs.rust-analyzer
|
||||||
|
];
|
||||||
|
shellHook = ''
|
||||||
|
echo "[shell.nix] Legacy shell for Rust dev. Use 'nix develop' for full flake support."
|
||||||
|
'';
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
// src/lib.rs
|
||||||
|
//! Console logging utilities for Rust applications.
|
||||||
|
|
||||||
|
use log::{Level, LevelFilter, Metadata, Record, SetLoggerError};
|
||||||
|
|
||||||
|
/// A minimal console logger implementation.
|
||||||
|
pub struct ConsoleLogger;
|
||||||
|
|
||||||
|
static LOGGER: ConsoleLogger = ConsoleLogger;
|
||||||
|
|
||||||
|
impl log::Log for ConsoleLogger {
|
||||||
|
fn enabled(&self, metadata: &Metadata<'_>) -> bool {
|
||||||
|
metadata.level() <= Level::Info
|
||||||
|
}
|
||||||
|
|
||||||
|
fn log(&self, record: &Record<'_>) {
|
||||||
|
if self.enabled(record.metadata()) {
|
||||||
|
println!("[{}] {}", record.level(), record.args());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn flush(&self) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Initializes the console logger with `Info` as the maximum log level.
|
||||||
|
pub fn init() -> Result<(), SetLoggerError> {
|
||||||
|
log::set_logger(&LOGGER)?;
|
||||||
|
log::set_max_level(LevelFilter::Info);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fn main() {
|
|
||||||
println!("Hello, world!");
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
#[test]
|
||||||
|
fn test_sample() {
|
||||||
|
assert_eq!(1, 1);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user