ggez | Rust library to create a Good Game Easily | Game Engine library
kandi X-RAY | ggez Summary
kandi X-RAY | ggez Summary
ggez is a Rust library to create a Good Game Easily. The current version is 0.6.0-rc1. This is a RELEASE CANDIDATE version, which means that the API should be stable but there are still known bugs to address. See the release milestone on the issue tracker for details. More specifically, ggez is a lightweight cross-platform game framework for making 2D games with minimum friction. It aims to implement an API based on (a Rustified version of) the LÖVE game framework. This means it contains basic and portable 2D drawing, sound, resource loading and event handling, but finer details and performance characteristics may be different than LÖVE. ggez is not meant to be everything to everyone, but rather a good base upon which to build. Thus it takes a fairly batteries-included approach without needing a million additions and plugins for everything imaginable, but also does not dictate higher-level functionality such as physics engine or entity component system. Instead the goal is to allow you to use whichever libraries you want to provide these functions, or build your own libraries atop ggez.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of ggez
ggez Key Features
ggez Examples and Code Snippets
Community Discussions
Trending Discussions on ggez
QUESTION
Currently, I'm working on a project where I use several crates that return different errors. I'm trying to not use unwrap on a result but instead passing the error upwards using the question mark syntax. To be able to do this I created my own error enum that has variants for the different types of errors from the different crates I'm using and then use map_err to map the errors to my error enum. I also decided that I should add the line and file where I remapped the error so I could see where I encountered the error.
My error enum ...ANSWER
Answered 2021-Feb-15 at 09:56An interesting implementation detail about enum variants, is that the initializers are actually functions.
We have another useful pattern that exploits an implementation detail of tuple structs and tuple-struct enum variants. These types use
()
as initializer syntax, which looks like a function call. The initializers are actually implemented as functions returning an instance that’s constructed from their arguments. We can use these initializer functions as function pointers that implement the closure traits, which means we can specify the initializer functions as arguments for methods that take closures– Advanced Functions and Closures - The Rust Programming Language
This means, that if you had an enum FooBar
, which had a variant Foo(i32, i32)
, then you could use and pass FooBar::Foo
as a Fn(i32, i32) -> FooBar
.
QUESTION
I am rather new to rust, so the following might also be a misunderstanding of a concept: I took the ggez basic project template from the basic project template which looks like this:
...ANSWER
Answered 2020-Jun-27 at 10:55I managed to figure it out, by reiterating through the rust documentation. Although it feels a little fishy to answer my own question it might actually be helpful for others:
TLDR; We want the code inside the main function to have access to MyGame but any other module outside denied access.
Can it be done with factoring out the code to game.rs
: No.
Can it be done at all: Yes.
Here is why and how:
From the rust documentation Visibility and Privacy:
With the notion of an item being either public or private, Rust allows item accesses in two cases:
- If an item is public, then it can be accessed externally from some module m if you can access all the item's parent modules from m. You can also potentially be able to name the item through re-exports. See below.
- If an item is private, it may be accessed by the current module and its descendants.
This means I cannot factor out horizontally and expect to limit horizontally at the same time. Since the main.rs
is on the top level anything on the same level that is public is accessible to the whole crate as any other module since every module can access the parent of the top level.
Therefore the answer for refactoring to the same level into a file (module) is: No.
On a side note, if I had factored out the code into a file called lib.rs
then the only difference would have been the path, as lib.rs
on the top level is implicitly just the crate
path, while in a file called game.rs
the path would be crate::game
.
But the same behavior as the single file can be done by factoring out vertically. We create a directory called game
and move game.rs
inside this directory and add the pub keyword to MyGame: pub struct MyGame
.
Similar to the python __init__.py
file rust needs a file mod.rs
to make the directory a module.
Inside the mod.rs
you declare the files you have inside, mod game
in our case.
Now we could address MyGame by the path crate::game::game::MyGame
, however since game.rs
is declared private the access to MyGame is sealed, as all elements of the path have to be public.
However, since MyGame is declared public, any module on the same level has access to it.
We cannot move the main.rs
into the game directory but we can factor the code inside it into another function. Let's call it init
for lack of fantasy. We put the init function inside a file called init.rs
inside the game directory and declare it public inside mod.rs
like so: pub mod init
.
Now we can call game::init::init()
because it is public, but not game::game::MyGame
. Init however, has access to MyGame
.
The final structure looks like this:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ggez
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page